多个文档(Word 2003 或 2007)使用一个中央页眉/页脚
在 Word(2003 或 2007)中,是否有一种方法可以让多个文档使用一个页眉/页脚?
我希望能够在一处更改页眉/页脚并使其影响多个文档。
即我有 50 个文档,它们都有相同的页眉/页脚。有没有办法将 50 个文档链接(OLE?)到一个主文档,而只需更改主文档,而不是打开所有 50 个文档进行更改?
如果没有内置的方法,有人用VBA做过这个吗?
Inside Word (2003 or 2007), is there a way to have one Header/Footer that is used by Multiple documents?
I want to be able to change the header/footer in one spot and have it affect multiple documents.
i.e. I have 50 documents and they all have the same header/footer. Instead of opening all 50 documents to make the change, is there a way to link (OLE?) the 50 documents to a main document and only have to change the main document?
If there is not a built in way, has anyone done this using VBA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这在实践中会如何运作,但您可以将其他文件作为链接插入到 Word 文档中。
首先创建包含页眉/页脚内容的文档,内容位于文档正文中。保存起来。
然后转到 50 个文档之一,进入页眉/页脚。转到插入|文件。找到第一个文件,然后单击“插入文件”对话框中“打开”按钮旁边的小下拉箭头。从下拉列表中选择“插入为链接”。内容现在应该显示在文档中。如果您单击内容,通常它会有灰色背景,表明它确实是一个 Word 字段。
现在,当您更改第一个文档时,您可以打开第二个文档,更新字段(单击其中的任意位置并按 F9),新内容将被拉入。您还可以非常简单地以编程方式更新字段,或者在“工具”|“工具”|“工具”下更新字段。选项 |打印,有一个框可以在每次打印文档时自动更新字段。
I'm not sure how will this will work in practice, but you can insert other files into a Word document as a link.
First create the document with the header/footer content, with the content in the body of the document. Save it.
Then go to one of your 50 documents, go into the header/footer. Go to INSERT | FILE. Locate the first file, then click the little drop-down arrow next to the OPEN button in the Insert File dialog. From the drop-down, select INSERT AS LINK. The content should now show up in the document. If you click in the content, normally it will have a grey background, to indicate it's really a Word field.
Now when you change the first document, you can open the second document, update the field (click anywhere in it and hit F9) and the new content will be pulled in. You can also update fields programmatically pretty easy, or under TOOLS | OPTIONS | PRINT, there's a box to auto update the fields every time the document is printed.
据我所知,(简单地)更改文档标题必须通过打开文档来完成。这就是说你有几个选择。首先,如果文档以 Office XML 格式保存,那么您可以使用 MSXML 库打开文件并更改标题中的数据。 (或者改变本质上是文本文件的数十种其他方法中的任何一种。)如果文件仍然是二进制格式,那么您实际上只有两个选择之一。第一种是通过 vba 打开文件并通过文档对象模型更改标头。第二个是找出二进制格式(已记录)并使用 VB6/VBA 本机二进制 IO 更改它(非常重要)。
除非我认为我可以获得更多时间,否则我会失去编写直接更改文档的代码的机会,否则我可能会循环遍历文件夹中的所有文件,打开它们并更改它们。至于将标题存储在某处......您可以将标题数据放入文本文件中并将其拉入。或者将文档模板保留在某处。
这是一个非常简单的例子:
AFAIK to alter a documents header (simply) must be done by having the document open. That said you have a few options. First if the documents are saved in the office XML format then you could open the files using the MSXML library and alter the data in the header. (Or any of the dozens of other ways to alter what is essentially a text file.) If the file(s) are still in the binary format you really only have one of two options. The first is to open the file via vba and alter the header via the document object model. The second would be to figure out the binary format (which is documented) and alter it using the VB6/VBA native binary IO (very non-trivial).
Unless I thought I could gain more time then I was going to lose writing code to alter the documents directly I would probably just loop through all the file in the folder, open them and alter them. As for storing the header somewhere... You could just put the header data in a text file and pull it in. Or keep a document template somewhere.
Here is a very trivial example: