从Word文件中提取特定文本 [英] Extracting specific text from a Word file

查看:605
本文介绍了从Word文件中提取特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Word文档,其字体大小为14和18,文档为1500页.

I have a Word document that has font sizes of 14 and 18, and the document is of 1500 pages.

我必须对字体14和18进行特定的更改,因此在搜索之后,我遇到了VBA for Word,这使我可以轻松地做到这一点.

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.

由于我以前从未做过VBA,所以我尝试了以下方法:

Since I have never done VBA before, I tried this:

Sub tryIt()

If Selection.Font.Size = 18 Then
MsgBox ("test")

End If
End Sub

但是它不起作用... msgbox()只是为了查看它是否正确识别了文本.

But it doesn't work... The msgbox() was just to see if it recognized the text properly.

那么我如何在Word文档中分隔/区分字体大小14和18,并在vb脚本中实现呢?

So how can I separate / differentiate between font size 14 and 18 in a Word document and implement this in a vb script?

有什么方法可以提取14和18大小的文本或进行搜索,以便我可以查找/替换?

Is there any way to extract the 14 and 18 sized text or search for it so that I can do a find/replace?

推荐答案

要准确地知道您要查找的内容有点棘手,但是下面的宏会将所有字体大小为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".

Sub TryIt()
With Selection.Find
    .ClearFormatting
    .Font.Size = 14
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = "fuzz"
    .Wrap = wdFindContinue
    .Format = True
    .Execute Replace:=wdReplaceAll
End With
End Sub

如果这不是您想要的,则可能需要澄清一下您的意思.

If this isn't what you're after, you may need to clarify a bit what you mean.

这篇关于从Word文件中提取特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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