Word VBA教程:Included属性

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


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





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
            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号