我在 Word 2003 中有一个宏,它将打开文档的属性字段应用于同一文件夹中的所有 .doc。该代码工作一次。如果我创建一个文件夹,在该文件夹中创建三个新文档,打开文档并运行宏,它将起作用。如果我在该文件夹中打开一个文档并再次运行宏,它只会更改运行宏的活动文档的属性。
该宏位于 Normal 模板的一个模块中。
编码:
title = ActiveDocument.BuiltInDocumentProperties("Title")
subject = ActiveDocument.BuiltInDocumentProperties("Subject")
author = ActiveDocument.BuiltInDocumentProperties("Author")
manager = ActiveDocument.BuiltInDocumentProperties("Manager")
company = ActiveDocument.BuiltInDocumentProperties("Company")
category = ActiveDocument.BuiltInDocumentProperties("Category")
keywords = ActiveDocument.BuiltInDocumentProperties("Keywords")
comments = ActiveDocument.BuiltInDocumentProperties("Comments")
fileDirectory = ActiveDocument.Path
vFile = Dir(fileDirectory & "\*.doc")
Do While vFile <> ""
Set wordDoc = Documents.Open(fileDirectory & "\" & vFile)
With wordDoc
.BuiltInDocumentProperties("Title") = title
.BuiltInDocumentProperties("Subject") = subject
.BuiltInDocumentProperties("Author") = author
.BuiltInDocumentProperties("Manager") = manager
.BuiltInDocumentProperties("Company") = company
.BuiltInDocumentProperties("Category") = category
.BuiltInDocumentProperties("Keywords") = keywords
.BuiltInDocumentProperties("Comments") = comments
.Save
.Close
End With
vFile = Dir
Loop
我不确定它是否与我打开或保存文件的方式有关。至少如果它根本不起作用,我会知道代码是错误的,但是因为它至少可以在新文档上运行一次......我不知道。
提前致谢。