none
How to hide header dialog on Word mail merge from vb.net 2010 RRS feed

  • Question

  • I have some Word documents that have merge fields for variable data.  The data for these documents comes from a batch process with multiple document types in a flat, delimited file.  The header information for these document types is in separate header files.  So, a single data file could have records for ADDH, LAWP, CORS, etc documents.  There is a separate Word document (a.g., ADDH.docx) and a separate header file (e.g., ADDHdescr.txt) for each type of document.  I want to automate the mail merge of these documents using a vb.net program.  I am able to do this when I have a data file with the header as the first record on the file.  But if I have a separate header file I get hung up because the document I have opened from within vb.net is trying to display the header dialog.   I was hoping to be able to read my data file, for each record parse out the document type, open the Word document, somehow set the header information, and then execute the mail merge.  When I try using the MailMerge.OpenHeaderSource command to indicate the header information, I get the dialog displayed.  It does not seem to have anywhere you can set the delimiter property.  Do you have any suggestions?

     


    Mary Leathem
    • Moved by Paul Zhou Monday, December 19, 2011 7:05 AM move for better support (From:.NET Base Class Library)
    Friday, December 16, 2011 6:55 PM

Answers

  • Hi Mary

    So far, I've only "dipped my big toe" into the Open XML world. I know what it should be good for, and I can manage to read it. But I've no experience in actually doing something with it.

    The best and first resource is OpenXMLDeveloper.org. There are example files as well as forums and I think there are a couple of examples for mail-merge types of things.

    What I can help you with (although slightly off-topic for this forum, as it's not really a "dev" discussion) is what to use as the "targets" for the data you want to feed into the documents. There are a number of possibilities, but what to use depends very much on how these documents are going to be created. Is this a single document that you're setting up? Do you have to work with "any document" a user gives you? Something else?


    Cindy Meister, VSTO/Word MVP
    Tuesday, December 20, 2011 2:53 PM
    Moderator

All replies

  • Hi Mary,

    I'm moving this thread to Word for Developers forum to get better support.

    Have a nice day.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 19, 2011 7:04 AM
  • Hi Mary

    The version Word does play a role in trouble-shooting and solution availability. It would be important for you to provide that information as part of your problem description...

    Historically, you can usually avoid the dialog box you describe by duplicating the header row as a "record" in the header file. Word won't do anything with it, it merely serves to confirm the information.

    However, mail merge is becoming less and less stable as time goes by, so there are no guarantees. And the above may not hold true if you have lots of field names or long field names (max number of characters).

    I should also warn you that Word was not designed to be run as a "server-side app". It's an end-user application and as such, will show dialog boxes and wait for user input. There's no way to guarantee this won't happen. The recommended and "correct" way to do batch files is to work directly with the Open XML file, using standard XML and "Packaging" tools (I'm talking .NET namespaces, here, but any tools that can work with XML and ZIP packages can do the job). This approach avoids the Word application entirely and is thus suited to non-attended execution - and will be MUCH faster.


    Cindy Meister, VSTO/Word MVP
    Monday, December 19, 2011 2:02 PM
    Moderator
  • Cindy,

      Thanks for your reply.  We are currtenly on Word 2007 and Visual Basic 2010.  I am not familiar with using Open XML.  I have been looking for information but am not clear how I would accomplish the equivalent of a mail merge using this approach.  Could you point me toward some articles that might help me?  Thanks.

    Mary


    Mary Leathem
    Tuesday, December 20, 2011 2:37 PM
  • Hi Mary

    So far, I've only "dipped my big toe" into the Open XML world. I know what it should be good for, and I can manage to read it. But I've no experience in actually doing something with it.

    The best and first resource is OpenXMLDeveloper.org. There are example files as well as forums and I think there are a couple of examples for mail-merge types of things.

    What I can help you with (although slightly off-topic for this forum, as it's not really a "dev" discussion) is what to use as the "targets" for the data you want to feed into the documents. There are a number of possibilities, but what to use depends very much on how these documents are going to be created. Is this a single document that you're setting up? Do you have to work with "any document" a user gives you? Something else?


    Cindy Meister, VSTO/Word MVP
    Tuesday, December 20, 2011 2:53 PM
    Moderator
  • Hi, Cindy,

       Thanks for getting back to me so quickly.  We have 279 different correspondence documents, all of which have variable merge fields.  These documents were developed in Lotus WordPro by our users and the data for whatever documents are generated each day in the daily batch come through on a flat file.  This file is currently run through a WordPro script to merge the data and generate and print the documents.  Our company is changing from WordPro to Microsoft Word as our primary word processor.  Our plan was to write a vb.net application to use the the Microsoft Office Interop Word assembly to open a Word document and perform the mail merge process using a data file as input.  This works successfully if the header information is in the file along with the data, but it requires additional manipulation and i-o and I had been hoping to avoid that by using the separate header file as I described above.  However, if using the mail merge and Microsoft Office Interop Word assembly  is not the way to go for the future, we may need to change this approach.  I will check out the site you suggested.  Thanks for your help.

    Mary


    Mary Leathem
    Tuesday, December 20, 2011 3:18 PM
  • Hi Mary

    For the moment, anyway, try my suggestion about "doubling up" the information in the header file. It would look something like this (assuming csv):

    Field1,Field2,Field3
    Field1,Field2,Field3

    Under normal circumstances, this should suppress the confirmation dialog box I think you're seeing (it could be you mean a different one than I'm thinking of).


    Cindy Meister, VSTO/Word MVP
    Tuesday, December 20, 2011 3:59 PM
    Moderator
  • Cindy,

       I tried doubling up the header file.  It eliminates the dialog box when I do the MailMerge.OpenHeaderSource but them I still get a dialog box when I do the MailMerge.OpenDataSource.  The only way I have been able to get it to work is to have the header record in the data file.

    Mary


    Mary Leathem
    Tuesday, December 20, 2011 5:35 PM
  • Hi Mary,

    Since it works OK if you have the header record in the data file, and both (it seems) are plain txt/csv files, why not append the data file to a copy of the header file, then use the consolidated file as the mailmerge data file?


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, December 21, 2011 7:00 AM
  • Hi, Paul.

       Yes, that works.  It's just that we have multiple header files required on any given night because we have multiple different documents coming in on the data file.  I can sort and split out the data and append the different header files to generate multiple input files and then merge each of these.   It just involves more I/O and seems to take a long time to run.  I had hoped to be able to read through the input file just once, merging each record with it's appropriate header and document, but I guess that might have taken a while to run too, if it worked.  Thanks for your input.

    Mary


    Mary Leathem
    Wednesday, December 21, 2011 2:11 PM