Modify query in Mail Merge in a Word document RRS feed

  • Question

  • i am creating a program where i made a word document in Word 2003 that is already set up for mail merge and saved as a .doc . and i would like to open the document in C# and beable to modify the query in the document and beable to save it again. does anyone have any ideas how about i can do this? i know how to modify it in .xml but i cant from a .doc and when i convert a .doc to a .xml i lose the query data

    i have word 2003 and VS 2005
    Thursday, August 6, 2009 8:41 PM


  • Hi Delsolice

    The best place to get help with the "how do I do it in Word" is the newsgroup for the application + topic. There's a word.mailmerge.fields newsgroup; you'll find a link in the forum's Please Read First message. They probably can't give you C# code, but the basic code you need won't be any different from the VB(A) that prevails there.

    FWIW, when a Word 2003 mail merge document is opened via the object model that link to the data source should be broken. This is a Security measure.

    So your code will probably need to hook up to the data source AND set the query.

    the best way to get the basic syntax is to record the actions in a VBA macro. As Word's mail merge data connection is a bit "finicky", you certainly need to record a macro to get the parameters for the OpenDataSource method. If the query is fairly simple, you can include the SELECT statement when you hook up to the data source.

    For any more detailed support, I recommend the newsgroup, as it's been quite a while since I worked with mail merge in any depth.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Friday, August 14, 2009 7:21 AM
    Friday, August 7, 2009 4:28 PM