0
votes

I am trying to delete all the words with font. name.FarEast="Georgia" and font.name="Verdana", Bold=true in the document, but I cannot find any find function for vba...(I'm ok with manually set the find formating) can anyone help me with that?

I have depleted my method of searching and could not find an answer

 With Selection.Find.Bold = True
        .ClearFormatting
        Selection.Font.NameFarEast = "Georgia"
       .Font.Name = "Verdana"
       .Execute FindText:="", ReplaceWith:="", Format:=True, _
        Forward:=True
        End With

'seems don't work at all

it just shows

"method or data not found"

1
For another time you can record the Find actions in a macro to get started. I imagine the problem with the code in the question is that a new line needs to come before .Bold = True. For future problems with error messages it would help us to mention which line of code causes the error. - Cindy Meister

1 Answers

0
votes

You can loop through all the words and check for the condition.

Sub test1()

Dim sen As Object
Dim wd As Object

For Each sen In ActiveDocument.StoryRanges(1).Sentences

    For Each wd In sen.Words

        With wd
        If .Bold = True  And .Font.Name = "Verdana" And .Font.NameFarEast = "Georgia" Then

            wd.Select
            Selection.Text = ""

        End If
        End With

    Next

Next

End Sub

Demo: Only Checking the Bold Words

enter image description here