AddSet Method

Microsoft Word Visual Basic

Adds a SET field to a mail merge main document. Returns a MailMergeField object. A SET field defines the text of the specified bookmark.

expression.AddSet(Range, Name, ValueText, ValueAutoText)

expression    Required. An expression that returns a MailMergeFields object.

Range    Required Range object. The location for the SET field.

Name    Required String. The bookmark name that ValueText is assigned to.

ValueText    Optional Variant. The text associated with the bookmark specified by the Name argument.

ValueAutoText    Optional Variant. The AutoText entry that includes text associated with the bookmark specified by the Name argument. If this argument is specified, ValueText is ignored.

Example

This example adds a SET field at the beginning of the active document and then adds a REF field to display the text after the selection.

Dim rngTemp as Range

Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)

ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _
    Name:="Name", ValueText:="Joe Smith"
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Fields.Add Range:=Selection.Range, _
    Type:=wdFieldRef, Text:="Name"