none
2010 Word VBA Reference: Importing Data into a MS Word Table RRS feed

  • Question

  • I write VBA for Excel, but I'm new to VBA for Word.  I'm trying to create a mail merge that will populate from one source and include a table on the same word document that will list records from another source.

    Can anyone point me to a good reference book or sample code dealing with importing data into a Word table using VBA?

    Thanks,

    Bob Sutor

    Saturday, March 2, 2013 9:05 AM

Answers

  • Using a DATABASE field to import the data would be predicated upon incorporating the field into the mailmerge that produces the  4-column table from your SQLData2 data source. That field would query your SQLData1 data source. No vba required. Peter Jamieson, at http://tips.pjmsn.me.uk/, probably knows more about the use of the DATABASE field than anyone else you might find.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by ConstPM Sunday, March 10, 2013 5:57 PM
    Saturday, March 2, 2013 8:14 PM

All replies

  • Depending on your requirements, you may be able to execute the merge in the document that creates the table and use a DATABASE field to import the data from the source that doesn't create the table. See: http://tips.pjmsn.me.uk/t0004.htm.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, March 2, 2013 11:43 AM
  • Still a bit confused.  Let me restate:

    1. I have a mail merge document that is using a SQL view (SQLData1) as a data source and works fine.
    2. Within the mail merge document I have a 4-column table.  I need to write VBA code which will fill the table with data from an separate data source (SQLData2).

    I hope this is clearer.  Any suggestions on the required VBA?

    Regards,

    ....bob

    File location:  c\Documents\WordTest\SQLTableImport.docx

    Table Index Number = 1

    Saturday, March 2, 2013 6:56 PM
  • Using a DATABASE field to import the data would be predicated upon incorporating the field into the mailmerge that produces the  4-column table from your SQLData2 data source. That field would query your SQLData1 data source. No vba required. Peter Jamieson, at http://tips.pjmsn.me.uk/, probably knows more about the use of the DATABASE field than anyone else you might find.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by ConstPM Sunday, March 10, 2013 5:57 PM
    Saturday, March 2, 2013 8:14 PM
  • Thanks for the help Paul.  It was very helpful.

    ...bob sutor

    Sunday, March 10, 2013 5:57 PM