![]() |
#36
|
|||
|
|||
![]()
Okay sorry for not being clear before.
Here is what I have now and it works! Code:
Sub CopyAndPaste() Dim myfile, wdApp As New Word.Application, wDoc As Word.Document 'select truck report file ChDrive "E:\" ChDir "E:\WG\TVAL\" myfile = Application.GetOpenFilename(, , "Browse for Document") Dim i As Integer 'searches for row with "avg" then selects column E(avg of temperature mean) of that row. i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0) 'makes the file appear wdApp.Visible = True Set wDoc = wdApp.Documents.Open(myfile) With wDoc Dim oRow As Row For Each oRow In wDoc.Tables(8).Rows If Len(oRow.Range) = 16 Then With oRow .Cells(1).Range.Text = "Performance Review" .Cells(2).Range.Text = "" .Cells(3).Range.Text = Range("e" & i) .Cells(4).Range.Text = "" .Cells(5).Range.Text = "" End With Exit For End If Next End With wDoc.Save End Sub All that is left that I would like to do is to change the background color if there is text in a row. I was thinking something like Code:
If Len(oRow.Range) >= 16 Then With oRow Shading.Texture = wdTextureNone Change.Shading.ForegroundPatternColor = wdColorAutomatic Change.Shading.BackgroundPatternColor = -603914241 End If End With All together it looks like this Code:
Sub CopyAndPaste() Dim myfile, wdApp As New Word.Application, wDoc As Word.Document 'select truck report file ChDrive "E:\" ChDir "E:\WG\TVAL\" myfile = Application.GetOpenFilename(, , "Browse for Document") Dim i As Integer 'searches for row with "avg" then selects column E(avg of temperature mean) of that row. i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0) Range("E" & i).Select Selection.Copy 'makes the file appear wdApp.Visible = True Set wDoc = wdApp.Documents.Open(myfile) With wDoc Dim oRow As Row For Each oRow In wDoc.Tables(8).Rows If Len(oRow.Range) = 16 Then With oRow .Cells(1).Range.Text = "Performance Review" .Cells(2).Range.Text = Range("e" & i) .Cells(3).Range.Text = "" .Cells(4).Range.Text = "" .Cells(5).Range.Text = "" End With End If Next If Len(oRow.Range) >= 16 Then With oRow Shading.Texture = wdTextureNone Change.Shading.ForegroundPatternColor = wdColorAutomatic Change.Shading.BackgroundPatternColor = -603914241 End If End With wDoc.Save End Sub |
Tags |
bookmark, if statement, vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
rebmaboss | Word | 1 | 11-25-2016 02:30 AM |
Pasting text from Excel cell into word without creating a table, and keeping the in-cell formatting | hanvyj | Excel Programming | 0 | 08-28-2015 01:15 AM |
How to insert a table using bookmarks in a document | Catty | Word VBA | 3 | 05-04-2015 03:05 AM |
![]() |
Niy | Word | 3 | 03-28-2012 12:18 AM |
Pasting table in Photoshop cutting off table | azdolfan | Word Tables | 0 | 05-16-2010 01:52 PM |