Trying to conditionally include the word doc into a word doc.

kmcaron

New Member
Joined
Aug 19, 2015
Messages
8
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
Using I am Word 2016, and trying to create a mail merge a document that conditionally include another mail merge document based on a mergefield. Both top document and included document use the same excel spreadsheet for the database to do the mail merge. The field is named "Joined" and when it is "xb" I want the other document included. Here is the Quick Part > Field that I created to do this:
{IF "< < Joined <joinws\><joined>> >" = "XB" {INCLUDETEXT "C\\USRS\\KCARON\\MYOPTIONAL.DOCX" \* MERGEFORMAT } "" \* MERGEFORMAT }</joined></joinws\>​
I never get the second document included, even when I hit a record where the Joined field is "xb"

I've recreated three files to demonstrate. I am new to this forum (first time posting). How do I include these files for others to look at?

Ken
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Your field should be coded as:
{IF{MERGEFIELD Joined}= "XB" {INCLUDETEXT "C\\USRS\\KCARON\\MYOPTIONAL.DOCX"}}
or:
{IF«Joined»= "XB" {INCLUDETEXT "C\\USRS\\KCARON\\MYOPTIONAL.DOCX"}}

Note1: 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); 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. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.

Note2: The IF test is case-sensitive. In your post you've referred to both XB and xb. You need to either:
• use the correct case for the data; or
• use a field switch in the Joined mergefield to force it to convert the text to whatever case you want to test against. For example:
{IF {MERGEFIELD Joined \* Upper}= "XB" {INCLUDETEXT "C\\USRS\\KCARON\\MYOPTIONAL.DOCX"}}
This approach is particularly useful if the data could exist in a mix of cases (e.g. XB, Xb, xb) and they should all be treated the same.

Note3: You don't need the \* MERGEFORMAT switches.
 
Last edited:
Upvote 0
Thank you!!

I got it to work. I think the "/* Upper" was what I was missing. I needed to add quotes around the MERGEFIELD value. Not sure what else happened it wasn't working so I entered it again (this time left the "/* MERGEFORMAT" in there. Once I jumped thru several records, it started working. I also did another INCLUDETEXT to optionally include a "new page". (actually the later started working first)

{IF "{ MERGEFIELD "JOINED" \* UPPER}" = "XB" {INCLUDE "C:\\USERS\\KCARON\\MYOPTIONAL.DOCX" \* MERGEFORMAT } "" } IF "{ MERGEFIEILD "JOINED" \* Upper }" = "XB" "<page break>" }
 
Upvote 0
You really don't need all those extra double-quotes or the \* MERGEFORMAT switch. And, if you want to insert a page break after the INCLUDETEXT field, use:
{IF{MERGEFIELD Joined \* Upper}= "XB" "{INCLUDETEXT "C\\USRS\\KCARON\\MYOPTIONAL.DOCX"}{QUOTE 12}"}
 
Upvote 0

Forum statistics

Threads
1,215,999
Messages
6,128,196
Members
449,432
Latest member
Novice Excel User

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top