InvalidComments 属性

       

如果 InvalidAddress 属性为 True,返回或设置说明无效地址错误的 String 值。可读写。

expression.InvalidComments

expression   必需。该表达式返回“应用于”列表中的一个对象。

说明

使用 SetAllErrorFlags 方法可设置数据源中所有记录的 InvalidAddressInvalidComments 属性。

示例

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

Sub ExcludeRecords()

    Dim intCount As Integer

    On Error Resume Next

    With ActiveDocument.MailMerge.DataSource
        .ActiveRecord = wdFirstRecord
        Do
            intCount = intCount + 1
            'Counts the number of digits in the postal code field and if
            'it is less than 5, the record is excluded from the mail merge,
            'marked as having an invalid address, and given a comment
            'describing why the postal code was removed
            If Len(.DataFields(6).Value) < 5 Then
                .Included = False
                .InvalidAddress = True
                .InvalidComments = "The zip code for this record" & _
                    "is less than five digits. This record is" & _
                    "removed from the mail merge process."
            End If

            .ActiveRecord = wdNextRecord
        Loop Until intCount >= .ActiveRecord
    End With

End Sub