Compartilhar via


MailMergeFields.AddNextIf Method

Word Developer Reference

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

Syntax

expression.AddNextIf(Range, MergeField, Comparison, CompareTo)

expression   Required. A variable that represents a MailMergeFields collection.

Parameters

Name Required/Optional Data Type Description
Range Required Range object The location for the NEXTIF field.
MergeField Required String The merge field name.
Comparison Required WdMailMergeComparison The operator used in the comparison.
CompareTo Required String The text to compare with the contents of MergeField.

Return Value
MailMergeField

Remarks

A NEXTIF field compares two expressions, and if the comparison is true, the next record is merged into the current merge document.

Example

This example adds a NEXTIF field before the first MERGEFIELD field in Main.doc. If the next postal code equals 98004, the next record is merged into the current merge document.

Visual Basic for Applications
  Documents("Main.doc").MailMerge.Fields(1).Select
Selection.Collapse Direction:=wdCollapseStart
Documents("Main.doc").MailMerge.Fields.AddNextIf _
    Range:=Selection.Range, MergeField:="PostalCode", _
    Comparison:=wdMergeIfEqual, CompareTo:="98004"

See Also