MailMergeDataSource.FieldNames property (Word)

Returns a MailMergeFieldNames collection that represents the names of all the fields in the specified mail merge data source. Read-only.

Syntax

expression. FieldNames

expression A variable that represents a 'MailMergeDataSource' object.

Remarks

For information about returning a single member of a collection, see Returning an object from a collection.

Example

This example displays the name of the first field in the data source attached to the active mail merge main document.

MsgBox ActiveDocument.MailMerge.DataSource.FieldNames(1).Name

This example uses the mNames() array to store the names of each merge field contained in the data source attached to the active document.

Dim mNames As Variant 
Dim mmTemp As MailMerge 
Dim intCount As Integer 
Dim intIncrement As Integer 
Dim mmfnLoop As MailMergeFieldName 
 
Set mmTemp = ActiveDocument.MailMerge 
intCount = _ 
 ActiveDocument.MailMerge.DataSource.FieldNames.Count - 1 
 
ReDim mNames(intCount) 
intIncrement = 0 
 
For Each mmfnLoop In mmTemp.DataSource.FieldNames 
 mNames(intIncrement) = mmfnLoop.Name 
 intIncrement = intIncrement + 1 
Next mmfnLoop

See also

MailMergeDataSource Object

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.