MailMergeDataSource![]() ![]() ![]() |
MappedDataField 对象的集合代表 Microsoft Word 中所有可用的映射数据字段。
使用 MailMergeDataSource 对象的 MappedDataFields 属性可返回MappedDataFields 集合。本示例创建一个 Word 中可用的映射数据字段和被映射的数据源中字段的制表符列表。本示例假定当前文档是邮件合并文档,并且数据源字段有相应的映射数据字段。
Sub MappedFields()
Dim intCount As Integer
Dim docCurrent As Document
Dim docNew As Document
On Error Resume Next
Set docCurrent = ThisDocument
Set docNew = Documents.Add
'Add leader tab to new document
docNew.Paragraphs.TabStops.Add _
Position:=InchesToPoints(3.5), _
Leader:=wdTabLeaderDots
With docCurrent.MailMerge.DataSource
'Insert heading paragraph for tabbed columns
docNew.Content.InsertAfter "Word Mapped Data Field" _
& vbTab & "Data Source Field"
Do
intCount = intCount + 1
'Insert Word mapped data field name and the
'corresponding data source field name
docNew.Content.InsertAfter .MappedDataFields( _
Index:=intCount).Name & vbTab & _
.MappedDataFields(Index:=intCount) _
.DataFieldName
'Insert paragraph
docNew.Content.InsertParagraphAfter
Loop Until intCount = .MappedDataFields.Count
End With
End Sub