Hi folks,
I am copying tables from excel using Paul's code below.
I modified it to use excel ranges that feed into each array.
The only issue I have now is it pastes the first table from excel into the first bookmark.
Then i get error - bad parameter on line
.MoveEnd wdTable, 1
https://www.msofficeforums.com/word-...cel-table.html
http://www.vbaexpress.com/forum/show...Tables-To-Word
Code:
Sub XLTablesWord()
Dim i As Long
Dim TableArray() As Variant
TableArray = Range("TableNames")
Dim BookmarkArray() As Variant
BookmarkArray = Range("BookmarkNames")
'---------PASTE TO DOCUMENT
With GetObject("C:\Users\Dan\Desktop\Tables.docx")
.Parent.Visible = True
For i = LBound(TableArray) To UBound(TableArray)
For Each sh In Sheets
For Each lob In sh.ListObjects
If TableArray(i, 1) = lob.Name Then
lob.Range.Copy 'Copy Table Range from Excel
With .Bookmarks(BookmarkArray(i, 1)).Range 'Paste Table into MS Word & format
.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
.MoveEnd wdTable, 1
.Tables(1).AutoFitBehavior (wdAutoFitWindow)
End With
End If
Next lob
Next sh
Next i
End With
End Sub
This has me stumped, I am not sure what the problem is
Many thanks for any advice
dan