0
votes

I want to generate a Ms Word documents with VBA using a template.
I need to import the Ms Word template it into excel (in a Sheet), manipulate it (by adding some data from other excel sheets) and then generate the word document. The problem is that I'm not able to copy the template in excel, it contains some tables and text, and when I try to copy/paste it doesn't keep the same formatting style ... I tried to use the Paste Option as mentionned Here but it doesn't solve the problem ...

Should I manipulate the template programatically with VBA and fill it directly from excel ?

1
Yes to the second option - that's going to work much better.Tim Williams
The problem is that the template contains some complex tables (nested) and i didn't even find a way to get the tables/cells/rows ID/INDEX ... that's why i thought to import the word doc into excel ...M3HD1
Thanks i already found that :p but still insufficient ... i really have many nested tables and i don't want to lose my time counting them ... and the code will not be generic if we made some changes in the template ...M3HD1
Have you looked into using bookmarks for this? Eg: ActiveDocument.Bookmarks("blah").Range.InsertAfter "Your text here"Tim Williams

1 Answers

0
votes

Finally I implemented Tim Williams solution : I copy the template, rename i, and fill it using the bookmarks I already defined :

    With myDoc.Bookmarks
       .Item("myBookmarkItem").Range.Text = "New Text"
    End With