Word VBA教程:Included属性

如果为该属性值为 True,则在邮件合并中包含记录。Boolean 类型,可读写。

expression.Included

expression   必需。该表达式返回一个MailMergeDataSource对象。

说明

使用SetAllIncludedFlags方法在邮件合并数据源中包括或排除所有记录。

VBA示例

本示例循环查看邮件合并数据源中的记录,检查邮政编码字段(本例中字段包含六位数字)是否包含少于五位数字。如果某记录的邮政编码字段包含少于五位数字,则从邮件合并中排除该记录,并标记该邮件地址为无效。


Sub CheckRecords()
    Dim intCount As Integer
    On Error Resume Next
    With ActiveDocument.MailMerge.DataSource
        'Set the active record equal to the first included record
        ' in the data source
        .ActiveRecord = wdFirstRecord
        Do
            intCount = intCount + 1
            'Set the condition that field six must be greater than
            'or equal to five
            If Len(.DataFields(6).Value) < 5 Then
                'Exclude the record if field six is less than five
                .Included = False
                'Mark the record as containing an invalid address field
                .InvalidAddress = True
                'Specify the comment attached to the record
                'explaining why the record was excluded
                'from the mail merge
                .InvalidComments = "The zip code for this record " & _
                    "is less than five digits. It will be removed " _
                    & "from the mail merge process."
            End If
            'Move the record to the next record in the data source
            .ActiveRecord = wdNextRecord
        'End the loop when the counter variable equals the
        'number of records in the data source
        Loop Until intCount = .RecordCount
    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号