Word 宏,将文件名添加到文件夹中一系列 Word 文档的正文中
我需要一个 Word 宏,将文档的文件名添加到该 Word 文档的第一行。但一次不仅仅是一份文档。我希望宏将这些文件名添加到特定文件夹中的一系列 Word 文档中(每个文档都有自己的文件名)。
将文件名添加到文档的宏很简单:
Selection.HomeKey Unit:=wdStory
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:= "FILENAME "
Selection.TypeParagraph
但是如何才能将文件名添加到文件夹中的整个文档系列呢?我想该文件夹可以在宏中命名。例如:C:\Users\用户名\Desktop\somefolder\
。我还认为可以使用循环来遍历文件夹,直到循环到达文件夹中文档的末尾。
I need a Word macro that adds the file name of a document to the first line of that Word document. But not just one document at a time. I would like the Macro to add these file names to a series of Word documents in a particular folder (with each document getting their own file name).
A Macro that adds the file name to document is simple:
Selection.HomeKey Unit:=wdStory
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:= "FILENAME "
Selection.TypeParagraph
But how can I get it to add file names to an entire series of documents in a folder? I suppose the folder could be named in the Macro. For example: C:\Users\username\Desktop\somefolder\
. I also suppose that a Loop could be used to go through the folder until the loop gets to the end of the documents in the folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这至少应该让你开始。我还没有测试过它,但我之前已经写过几次这种类型的东西,所以基本的想法是有效的。
This should at least get you started. I haven't tested it, but I've written this type of thing a few times before, so the basic idea works.