Included 属性

       

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

expression.Included

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

说明

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

示例

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

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