Search code examples
excelms-wordmailmerge

Mail Merge using one Word doc but needing many iterations depending on Excel data


This is an updated post from today as the parameters have changed.

I have an Excel sheet with the data. I have a Word document that instructs me to choose which paragraph to use based on the data in Excel. For instance, if the NewClient column in Excel has an X, then I choose paragraph 2 for the letter. If it is blank I choose paragraph 1. If it has a Y, then I choose paragraph 3. I have several instances in this document where I have three things to choose from. Is there a way to do this via mail merge? I've been reduced to adding columns and filling them with the various paragraphs. That "works" but it isn't the solution my bosses want. They think that we can somehow use fields and if...then...else to make this Word document magically be produced in each instance.


Solution

  • Conditionally varying text in a mailmerge is a trivial programming task - all done via field coding. For example:

    {IF{MERGEFIELD NewClient}= "X" "NewClient Text for X"}{IF{MERGEFIELD NewClient}= "Y" "NewClient Text for Y"}{IF{MERGEFIELD NewClient}= "" "NewClient Text for blank"}
    

    Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. The conditional output can include multiple paragraphs, tables and images, if needed.