Word VBA教程:BuiltInDocumentProperties属性

来源:百度文库 编辑:神马文学网 时间:2024/04/28 10:06:38
返回一个DocumentProperties集合,该集合代表了指定文档的所有内置的文档属性。
expression.BuiltInDocumentProperties
expression   必需。该表达式返回“应用于”列表中的一个对象。
说明
若要返回代表指定内置文档属性的单一DocumentProperty对象,请使用 BuiltinDocumentProperties(index),其中 index 是一个 WdBuiltInProperty 常量。如需获得有效常量的列表,请参考 Microsoft Visual Basic对象浏览器。有关返回集合中单个成员的内容,请参阅返回集合中的对象。
如果 Microsoft Word 没有为一个内置的文档属性定义一个值,则读取这个文档属性的Value属性时会产生一个错误。
用CustomDocumentProperties属性返回自定义文档属性的集合。
VBA示例
本示例在活动文档的末尾插入一个内置属性列表。
Sub ListProperties()Dim rngDoc As RangeDim proDoc As DocumentPropertySet rngDoc = ActiveDocument.ContentrngDoc.Collapse Direction:=wdCollapseEndFor Each proDoc In ActiveDocument.BuiltInDocumentPropertiesWith rngDoc.InsertParagraphAfter.InsertAfter proDoc.Name & "= "On Error Resume Next.InsertAfter proDoc.ValueEnd WithNextEnd Sub
本示例显示活动文档中的单词数。
Sub DisplayTotalWords()Dim intWords As IntegerintWords = ActiveDocument.BuiltInDocumentProperties(wdPropertyWords)MsgBox "This document contains " & intWords & " words."End Sub