Microsoft Word 提供了一些可在 Word 文档中设置的默认文档属性。 vbscript 有许多默认属性,其中有常量。 但是 Word (2011) 提供了更多属性,例如公司传真号码、发布日期、关键字。
可以通过调用来访问内置属性
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open(strFilePath)
For Each prop In oWord.ActiveDocument.BuiltInDocumentProperties
WScript.Echo prop.Name + "::" + oWord.ActiveDocument.BuiltInDocumentProperties(prop.Name).Value
Next
但是我如何找到由 word 提供但在 vbscript 中不作为常量存在的“自定义”属性的名称? 有这个功能
Document.CustomDocumentProperties
但是如果我像上面那样进行列表,我会得到名为 info1、info2 等的属性。
最佳答案
要访问 Word CustomDocumentProperties,您还需要能够访问 OLE 文件属性读取器。这超出了普通/简单文档属性的范围,因为它也允许您添加自定义属性。
2005 年有一篇来自 Script 的故事文章,详细介绍了在 Word 中使用 CustomDocumentProperties 的安装和使用方法 -> Here
要下载安装 OLE 属性读取器 DLL,请转至 -> Here
以下是安装属性读取后设置/获取属性的示例:
Const msoPropertyTypeBoolean = 2
Set objFile = CreateObject("DSOFile.OleDocumentProperties")
objFile.Open("C:\Scripts\New_users.xls")
'Set
'=======================================================================
objFile.CustomProperties.Add "Document Reviewed", msoPropertyTypeBoolean
objFile.Save
'Get
'=======================================================================
Set objProperty = objFile.CustomProperties.Item("Document Reviewed")
wscript.echo objProperty.Value
享受吧!
关于vbscript - 如何在vbscript中读写word文件的非标准文档属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784719/