Search for Font Color

D

dsc

I suspect this is blindingly obvious, but I just can't figure it out.

The Word replace dialog allows you to specify a font color and search for
text only of that color, such as every instance of the word "the" that is in
red text.

Could somebody please tell me how you do that from a macro?

Thanks for any assistance.
 
S

Shauna Kelly

Hi dsc

The following will find red "the"s and replace them with blue "xxx"s. If you
don't need to replace, then leave out the whole With .Replacement .... End
With section. And, just .Execute without .Execute Replace:=wdReplaceAll.

Sub FindRedThe()

With Selection.Find
'Clear out old stuff
.ClearFormatting

'Set the search string
.Text = "the"

'Go forward from the selection and
'then wrap throughout the document
.Forward = True
.Wrap = wdFindContinue

'Require Word to search for formatting
.Format = True

'Set the format to find
.Font.Color = wdColorRed

'Set the replacement requirements
With .Replacement
.ClearFormatting
.Text = "xxx"
.Font.Color = wdColorBlue
End With

'Go!
.Execute Replace:=wdReplaceAll
End With

End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
D

dsc

Thanks, Shauna.

Actually, while it wasn't quite the solution, it did turn on the lightbulb
finally.

I just have to go through and turn everything to be changed to one color,
then go through again searching for that color and change what needs to be
changed.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top