Word VBA教程:MappedDataFields集合

   
MailMergeDataSource
MappedDataFields
MappedDataField

MappedDataField对象的集合代表 Microsoft Word 中所有可用的映射数据字段。

使用 MappedDataFields集合

使用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

Word VBA教程

Word VBA参考教程:目录1 Word VBA参考教程:目录2
Word VBA参考教程:目录3 Word VBA参考教程:目录4
Word VBA参考教程:目录5 Word VBA参考教程:目录6
Word VBA参考教程:目录7 Word VBA参考教程:目录8
Word VBA参考教程:目录9 Word VBA参考教程:目录10
版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号