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.
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
>I suspect this is blindingly obvious, but I just can't figure it out.
>
[quoted text clipped - 5 lines]
>
> Thanks for any assistance.
dsc - 21 Dec 2004 13:03 GMT
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.
> Hi dsc
>
[quoted text clipped - 50 lines]
>>
>> Thanks for any assistance.