L
Legacy 306721
Guest
How does one insert an Excel data range to a Word bookmark? Here is my attempt so far:
I've tried incorporating bookmarks but have had no luck.
Code:
Sub CopyToWord()
Dim wdApp As Object
Dim wdDoc As Object
Dim xlRng As Excel.Range
Dim file_extension As String
ReDim Tables(1 To 16) As String 'an array of 16 variables
'ranges of tables 1 through 16. Tables(k) = "Range of Table k"
Tables(1) = "B3:E15"
Tables(2) = "B19:E31"
' Tables(3) = "G19:J31"
' Tables(4) = "B36:E48"
' Tables(5) = "G36:J48"
' Tables(6) = "B52:E64"
' Tables(7) = "G52:J64"
' Tables(8) = "B68:E80"
' Tables(9) = "G68:J80"
' Tables(10) = "B84:E96"
' Tables(11) = "G84:J96"
'Tables 2 worksheet
' Tables(12) = "B3:Q16"
'Tables 3 worksheet
' Tables(13) = "B3:AC16"
' Tables(14) = "B22:AC35"
'Tables 4 worksheet
' Tables(15) = "B2:E74"
' Tables(16) = "K2:N169"
'Word document to which you want to copy - use the entire file extension
file_extension = "C:\Users\blah"
'Open Word
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.documents.Open(file_extension)
wdApp.Visible = True
Dim xlRng1 As Excel.Range
Set xlRng1 = Range(Tables(1))
xlRng1.Copy
wdDoc.Content.PasteExcelTable False, False, True
End Sub
I've tried incorporating bookmarks but have had no luck.