Share via


TextRange.InsertMailMergeField Method

Publisher Developer Reference

Returns a TextRange object that represents a text data field for a mail merge or catalog merge.

Syntax

expression.InsertMailMergeField(varIndex)

expression   A variable that represents a TextRange object.

Parameters

Name Required/Optional Data Type Description
varIndex Required Variant The name or index of the data field in the datasource.

Return Value
TextRange

Remarks

For a publication's catalog merge area to contain text data fields, it must first contain at least one text box to contain the text data fields.

Example

This example inserts a LastName field at the cursor position. This example assumes that the active publication is a mail merge publication and that the cursor position is somewhere inside a text box.

Visual Basic for Applications
  Sub InsertMergeField()
    Selection.TextRange.InsertMailMergeField varIndex:="LastName"
End Sub

This example adds a text box to the specified publication's catalog merge area, and then inserts a text data field into the text box. This example assumes that the specified publication is connected to a data source, and that it contains a catalog merge area.

Visual Basic for Applications
  Set pbTextBox1 = ThisDocument.Pages(1).Shapes.AddTextbox(1, 100, 100, 175, 25)
pbTextBox1.AddToCatalogMergeArea

With pbTextBox1.TextFrame.TextRange .Text = "List Price: " .InsertMailMergeField "List Price" End With

See Also