使用VBA解析MS Word文档中的文本 [英] Using VBA to parse text in an MS Word document

查看:92
本文介绍了使用VBA解析MS Word文档中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以为MS Word宏提供帮助.

I was hoping someone could help with a MS Word Macro.

基本上,我有一个MS Word文档,其中列出了几个文本文件以及每个文件中的特定感兴趣页面.

Basically, I have a MS Word document which lists out several text files and specific pages of interest in each file.

文件格式类似于:


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.

但是我停留在第1步,如何将行捕获到MS Word宏中的字符串中?

But I'm stuck at step 1, how do I capture the line into a string in an MS Word Macro?

任何帮助将不胜感激.

推荐答案

以下代码应使您入门:

Public Sub ParseLines()
    Dim singleLine As Paragraph
    Dim lineText As String

    For Each singleLine In ActiveDocument.Paragraphs
        lineText = singleLine.Range.Text

        '// parse the text here...

    Next singleLine
End Sub

我在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆