none
Merge two speacial WORD documents using VBA RRS feed

  • Question

  • I have two WORD documents.  For the sake of discussion, I will call them OTHER.doc and TABLES.doc.  I want to merge them and create MERGED.doc.  TABLES.doc contain tables, but before each table is text that says TABLE x STARTS HERE.  x is 1, 2, 3, etc.  OTHER.doc has all the other text, but every so often, there is a line that says TABLE x GOES HERE.  I'm pretty good at writing VBA WORD macros, but I need a bit of help in knowing which commands to use:  I can find the text, and probably position myself in the first cell of the table, but what is the command to "grab" the whole table.  Also, what is the command to insert it into the merged document?  I hope this is clear enough.  If not, please contact me and I will amplify.  Thanks.  - Ron
    Wednesday, September 11, 2013 5:04 PM

Answers

  • Hi Ron

    If you have a selection or a Range in a table, then you can pick up the entire table by doing this:

    Dim tbl as Word.Table
    Set tbl = Selection.Tables(1) 'key is Tables(1): gets the first table in the Range or Selection

    In a general sort of way, you should be able to copy the table from one place to another using the FormattedText property. Assuming you've used Selection.Find to pick up the "goes here" and want to replace that with the table, it would look like this:

    Selection.Range.FormattedText = tbl.Range.FormattedText


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, September 12, 2013 7:44 AM
    Moderator