Word macro search & replace text only if original text is bold

I have a document which has comments in bold on some lines, and I need to change the bold text to other text, and retain the bold styling.

I know how to find and replace text in a macro, but not how to determine whether the text is bold so that only the bold text is changed.

Any ideas?
LVL 3
jdthedjAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SimonConnect With a Mentor Commented:
It's  the Format:=True of the .Find.Execute method that you need
See the MSDN reference for the FIND method.
This other MSDN link has examples with formatting
The final example is very close to what you need to do....
With ActiveDocument.Content.Find
    .ClearFormatting
    .Font.Bold = True
    With .Replacement
        .ClearFormatting
        .Font.Bold = TRUE
    End With
    .Execute FindText:="Comment", ReplaceWith:="ReplacementComment", _
        Format:=True, Replace:=wdReplaceAll
End With

Open in new window

0
 
jdthedjAuthor Commented:
Thanks very much Simon - exactly what I need, and a very full answer.
0
All Courses

From novice to tech pro — start learning today.