Dzwebs.Net

撰写电脑技术杂文十余年

word之VBA RecordCount属性使用示例

Admin | 2012-11-30 8:35:55 | 被阅次数 | 4798

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  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 位,就将其从邮件合并中删除。


该杂文来自: Word杂文

上一篇:word域的概念、作用及使用范例

下一篇:word空格变方框

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计