TextRange.InsertMailMergeField method (Publisher)

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


expression.InsertMailMergeField (varIndex)

expression A variable that represents a TextRange object.


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

Return value



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.


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.

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) 
With pbTextBox1.TextFrame.TextRange 
 .Text = "List Price: " 
 .InsertMailMergeField "List Price" 
End With 

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.