![]() |
|
#1
|
|||
|
|||
|
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
Many thanks for any advice dan |
|
#2
|
||||
|
||||
|
The only error I can see as likely to be generated on that line is 'variable not defined' - and then only if you haven't set a reference to the Word object library.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hi Paul,
that seemed to do the trick set the reference to the Word Library but sadly another error has appeared. For some reason it is skipping the middle table example Arrays Set Up like this Table1 ------BM1 Table2 ------BM2 Table3 ------BM3 Table3 - gets pasted into BM2 and nothing in BM3 any ideas? thank you dan |
|
#4
|
||||
|
||||
|
Without actually seeing the problem Word document and Excel workbook, it can be difficult for anyone to diagnose the issue. Can you attach a document & workbook to a post with some representative content (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How can I paste text that's not formatted as a table into a new table?
|
WaltR | Word | 2 | 10-11-2014 03:16 PM |
How to paste the data from one table into the cells of another table, without overwriting anything
|
CClio333 | Word Tables | 1 | 08-12-2014 05:17 PM |
Is it possible to copy non-contiguous rows of a Table and paste them as a separate Table in Word?
|
Joey Cheung | Word Tables | 1 | 08-12-2014 05:15 PM |
Can pass .expression as a parameter?
|
tinfanide | PowerPoint | 4 | 12-28-2012 06:14 PM |
| Word 2003 Table of Contents Error Message | ktcolburn | Word | 1 | 10-30-2005 06:14 PM |