gpt4 book ai didi

vba - 使用 VBA 解析 MS Word 文档中的文本

转载 作者:行者123 更新时间:2023-12-04 19:59:13 26 4
gpt4 key购买 nike

我希望有人可以帮助使用 MS Word 宏。

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

文件格式类似于:

textdocument1.txt P. 6, 12 - issue1
textdocument2.txt 第 5 页 - 问题 1
第 13、17 页 - 第 3 期
textdocument3.txt 第 10 页

我想将每一行作为字符串读入我的宏。

然后遍历它来识别文件名。有了文件名,我就可以打开文件,转到页码,然后复制我需要的数据。

但是我被困在第 1 步,如何在 MS Word 宏中将该行捕获为字符串?

任何帮助将不胜感激。

最佳答案

以下代码应该可以帮助您入门:

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

我在 this article 中找到了基本算法.

关于vba - 使用 VBA 解析 MS Word 文档中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/756990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com