![]() |
|
#2
|
||||
|
||||
|
Assuming your bookmarks d5, d20 & D22 refer to the column and row of the word table then also assuming that the value of 'i' is correctly resolved (we don't have your sheet to test) then the following should work . Depending on what is in Range("E" & i) you don't have to select and copy it. Just write its content to the Word table.
The code uses late binding to Word and so does not need a reference to Word. Code:
Sub CopyAndPaste()
Dim myfile, wdApp As Object, wdDoc As Object
Dim oRng As Object
Dim i As Integer, iRow As Integer
'select truck report file
ChDrive "E:\"
ChDir "E:\WG\TVAL\"
myfile = Application.GetOpenFilename(, , "Browse for Document")
'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)
'copies the cell - not necessary if you simply write the range
Range("E" & i).Copy
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(myfile)
iRow = Range("c2")
If iRow < 0 Then iRow = Range("c2") * -1
Set oRng = wdDoc.Tables(1).Cell(iRow, 5).Range
oRng.End = oRng.End - 1
oRng.Text = Range("E" & i)
'or
'oRng.Paste
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Having Issues Applying a Macro Across Multiple Files. Changes Just Don't Seem To Save. | Kajex | Word VBA | 2 | 09-08-2017 06:37 AM |
| Applying heading style to multiple pages at once | jane.bugai | Word | 5 | 02-24-2017 04:05 PM |
Form updating Bookmarks - writes to the bookmarks multiple times
|
PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |
Applying a conditional format to multiple rows
|
secoo140 | Excel | 1 | 10-12-2013 07:19 PM |
| Publisher 2000 - Applying multiple styles | Jerb | Publisher | 0 | 02-15-2009 10:06 AM |