Extract specific text from a Word file

I have a Word document whose font size is 14 and 18 and the document is 1,500 pages.

I need to make specific changes to font 14 and font 18, and so after searching I came across VBA for Word, which would allow me to do this easily.

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

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

But that will not work ... msgbox () just to find out if it recognized the text correctly.

So, how can I split / delimit the font size of 14 and 18 in a Word document and implement this in a vb script?

Is there a way to extract text in sizes 14 and 18 or look for it so that I can find / replace?

0
source share
2 answers

You did not say that it does not work with your code. However, to get started, try the following:

 Sub tryIt() Dim findRange As Range Set findRange = ActiveDocument.Range findRange.Find.ClearFormatting findRange.Find.Font.Size = 18 Do While findRange.Find.Execute(findtext:="") = True findRange.Select 'Do something here DoEvents Loop End Sub 
0
source

It’s a little difficult to tell exactly what exactly is after you, but the following macro will replace all the continuous text in 14 fonts 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 is not what you need, you may need to clarify a little what you mean.

0
source

Source: https://habr.com/ru/post/949183/


All Articles