MailMergeFields.AddIf (Word)

Adds an IF field to a mail merge main document. Returns a MailMergeField object.

When updated, an IF field compares a field in a record with a specified value, and then it inserts the appropriate text according to the result of the comparison.

AddIf (Range, MergeField, Comparison, CompareTo, TrueAutoText, TrueText, FalseAutoText, FalseText)


ActiveDocument.MailMerge.Fields.AddIf Range:=Selection.Range, _ 
 MergeField:="Company", Comparison:=wdMergeIfIsBlank, _ 
 TrueText:="for your personal use", _ 
 FalseText:="for your business"

Arguments

The following arguments are required:

Range (Range) - The location for the IF field.

MergeField (String) - The merge field name.

Comparison (WdMailMergeComparison) - The operator used in the comparison.


Possible values are

wdMergeIfEqual A value is output if the mail merge field is equal to a value.
wdMergeIfGreaterThan A value is output if the mail merge field is greater than a value.
wdMergeIfGreaterThanOrEqual A value is output if the mail merge field is greater than or equal to a value.
wdMergeIfIsBlank A value is output if the mail merge field is blank.
wdMergeIfIsNotBlank A value is output if the mail merge field is not blank.
wdMergeIfLessThan A value is output if the mail merge field is less than a value.
wdMergeIfLessThanOrEqual A value is output if the mail merge field is less than or equal to a value.
wdMergeIfNotEqual A value is output if the mail merge field is not equal to a value.

Optional arguments

The following arguments are optional

CompareTo (String) - The text to compare with the contents of MergeField.

TrueAutoText (String) - The AutoText entry that's inserted if the comparison is true. If this argument is specified, TrueText is ignored.

TrueText (String) - The text that's inserted if the comparison is true.

FalseAutoText (String) - The AutoText entry that's inserted if the comparison is false. If this argument is specified, FalseText is ignored.

FalseText (String) - The text that's inserted if the comparison is false.