电脑教程
位置:首页>> 电脑教程>> office教程>> word之VBA RecordCount属性使用示例

word之VBA RecordCount属性使用示例

  发布时间:2023-12-14 06:36:28 

标签:word之VBA,RecordCount属性使用示例

word中的vba里面的RecordCount属性,其功能是返回一个 Long对象,该对象代表数据源中记录的数字为只读。

语法如下:

expression.RecordCount

参数说明

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

注意:

如果 Microsoft Word 不能确定数据源中记录的数字,RecordCount属性会返回值 -1。

以下内容是有关RecordCount的代码示例

On Error GoTo ErrorHandler

With ActiveDocument.MailMerge.DataSource

.ActiveRecord = wdFirstRecord

Do

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

If .ActiveRecord <> .RecordCount Then

.ActiveRecord = wdNextRecord

End If

Loop Until .ActiveRecord = .RecordCount

ErrorHandler:

End With

上面的代码循环遍历数据源中的记录并验证邮政编码域(在本示例中是第六个域)是否少于五位,如果少于五位,则从邮件合并中删除该记录。

如果要确保将定位代码添加到邮政编码中,可以将长度值从 5 改为 10。从而,如果邮政编码少于 10 位,就将其从邮件合并中删除。

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com