Question

I am new to mail merge process and commands. I have a word template document which is used as source for mail merging. In this document they have used IF statement in various places. When I open the document in the word It looks like the below:

enter image description here

As you can see in the image, simple merge fields are surrounded by "<<" ">>".

"Member Maintenance" and "Other Amendments" are actually IF merge field. If I right click over them and select "Toggle Field Codes", It shows the actual IF statement.

enter image description here

The actual If statement is showing up after selecting Togggle Field Codes

enter image description here

I would like to know how do they label the whole IF statement with the word "Other Amendments"

I tried adding my own IF statement using Ctrl+F9, but they are not visible after I typed, I had to use the Alt+F9 to make them visible.

I want to add labeled IF statements like the above "Other Amendments"

Was it helpful?

Solution

I don't think these are really "labelled IF statements" - what the creator of the template has probably done is to replace the result text of the IF field by the text they want the user to see. If you preview the merge document and move to the next or previous record, my guess is that you will see the text change to be the result of the field, and when you move back to the record you started with, you will no longer see this placeholder text.

From a programming point of view, you could for example replace all the result texts with your own "placeholder" using, e.g.

Dim f As Word.Field
For Each f In ActiveDocument.Fields
  If f.Type = Word.WdFieldType.wdFieldIf Then
    f.Result.Text = "my placeholder text"
  End If
Next

But in fact, you can replace the result text manually by, e.g. clicking inside the text, typing your own text, then deleting all the old text (carefully, or you may delete the field). If you do that, this isn't a programming question and would be out of scope for StackOverflow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top