使用 VBA 解析 MS Word 文档中的文本
我希望有人可以帮助使用 MS Word 宏。
基本上,我有一个 MS Word 文档,其中列出了几个文本文件以及每个文件中感兴趣的特定页面。
文件格式类似于:
textdocument1.txt P. 6, 12 - issue1 textdocument2.txt P. 5 - issue1 P. 13, 17 - issue3 textdocument3.txt P. 10
我想将每一行作为字符串读入我的宏。
然后遍历它来识别文件名。 有了文件名,我就可以打开文件,转到页码,然后复制我需要的数据。
但我陷入了步骤 1,如何将该行捕获到 MS Word 宏中的字符串中?
任何帮助将不胜感激。
I was hoping someone could help with a MS Word Macro.
Basically, I have a MS Word document which lists out several text files and specific pages of interest in each file.
The file format is similar to:
textdocument1.txt P. 6, 12 - issue1 textdocument2.txt P. 5 - issue1 P. 13, 17 - issue3 textdocument3.txt P. 10
I want to read each line into my Macro as a string.
Then traverse through it to identify the file name. With the file name, I can then open the file, go to the page number, and copy the data I need.
But I'm stuck at step 1, how do I capture the line into a string in an MS Word Macro?
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下代码应该可以帮助您入门:
我在 本文。
The following code should get you started:
I found the basic algorithm in this article.
如果您的 Word 文档列出了如下所示的所有文本文件:
那么所有行都可以在 段落集合。 您可以使用简单的
For Each
循环来遍历它:If your word document lists all the text files like this:
Then all the lines are available in the Paragraphs collection. You can loop through that with a simple
For Each
loop:每行
per line
如果文本是其他包含特殊字符或使用另一种语言,则上述代码将不起作用,这是我在执行的一项任务中提出的解决方案
if text is in other contains special character or is in another language the above code will not work this was the solution i came up with on one of task i performed