从Word文件中提取特定文本
我有一个Word文档,字体大小为14和18,文档有1500页。
我必须对字体 14 和字体 18 进行特定更改,因此在搜索后,我发现了 VBA for Word,它可以让我轻松地完成此操作。
由于我以前从未做过VBA,所以我尝试了这个:
Sub tryIt()
If Selection.Font.Size = 18 Then
MsgBox ("test")
End If
End Sub
但是它不起作用... msgbox() 只是为了看看它是否正确识别了文本。
那么如何在Word文档中分离/区分字体大小14和18并在vb脚本中实现呢?
有没有办法提取 14 和 18 大小的文本或搜索它,以便我可以进行查找/替换?
I have a Word document that has font sizes of 14 and 18, and the document is of 1500 pages.
I have to make specific changes to the font 14 and font 18, and so after searching, I came across VBA for Word that would allow me to do this easily.
Since I have never done VBA before, I tried this:
Sub tryIt()
If Selection.Font.Size = 18 Then
MsgBox ("test")
End If
End Sub
But it doesn't work... The msgbox() was just to see if it recognized the text properly.
So how can I separate / differentiate between font size 14 and 18 in a Word document and implement this in a vb script?
Is there any way to extract the 14 and 18 sized text or search for it so that I can do a find/replace?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有说什么不适用于您的代码。但是,对于初学者来说,请尝试以下操作:
You didn't say what wasn't working with your code. However, for starters try this:
确切地说出您想要的内容有点棘手,但以下宏会将字体大小为 14 的所有连续文本替换为文本“fuzz”。
如果这不是您想要的,您可能需要澄清一下您的意思。
It's a bit tricky to tell what you're after exactly, but the following macro will replace all contiguous text that is in font size 14 with the text "fuzz".
If this isn't what you're after, you may need to clarify a bit what you mean.