0
votes

I have a word file containing over 20 tables. I want to insert a named range (or a table) from excel into the word file just before the 13th table. I do not want the new table to merge with any existing tables. I am using VBA to do this. The problem is the inserted table gets merged with the table(13).

// Yakuza is the name of my named range

Set tbl = ThisWorkbook.Worksheets(Sheet2.Name).Range("Yakuza")
    tbl.Copy
    objDoc.Tables(tblno).Range.InsertBefore (Chr(10))
    objDoc.Tables(13).Range.PasteExcelTable False, False, False

//I have tried this as well: objDoc.Tables(tblno).Range.PasteAndFormat wdFormatOriginalFormatting
1

1 Answers

0
votes

To prevent the tables merging, you need to have an ordinary paragraph between them. Hence:

objDoc.Tables(tblno).Range.Characters.First.Previous.InsertBefore vbCr & vbCr
objDoc.Tables(tblno).Range.Characters.First.Previous.Previous.PasteExcelTable False, False, False