Publisher (的 MailMergeDataSource.RecordCount 屬性)
會傳回 Long ,代表的資料來源中的記錄數目。 唯讀。
語法
運算式。RecordCount
表達 代表 MailMergeDataSource 物件的 變數。
傳回值
Long
範例
此範例會驗證附加資料來源中五位數的 ZIP 代碼。 如果 ZIP 程式碼的長度少於五位數,則記錄會從合併列印程式中排除。
此範例假設郵遞區號為美國郵遞區號。 您可以修改此範例來搜尋將 4 位數定位器程式碼附加至 ZIP 程式碼的 ZIP 程式碼,然後排除所有不包含定位器程式碼的記錄。
Sub Validate
Dim intCount As Integer
With ActiveDocument.MailMerge.DataSource
'Set the active record equal to the first included record in the
'data source
.ActiveRecord = 1
Do
intCount = intCount + 1
'Set the condition that field six must be greater than or
'equal to five digits in length
If Len(.DataFields.Item(6).Value) < 5 Then
'Exclude the record if field six contains fewer than five digits
.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 has " _
& "fewer 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 = .ActiveRecord + 1
'End the loop when the counter variable
'equals the number of records in the data source
Loop Until intCount = .RecordCount
End With
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。