InsertMailMergeField Method

Microsoft Publisher Visual Basic

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

expression.InsertMailMergeField(varIndex)

expression    Required. An expression that returns one of the objects in the Applies To list.

varIndex   Required Variant. The name or index of the data field in the datasource.

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 insertion point is somewhere inside a text box.

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.

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