Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing highlighted text to a different color

Tags:

I have some simple .doc files I made in Word 2007 where I changed the text color and used highlights to compare some similar texts. What I'd like to do is change any instances of green text or gray highlighting to different respective colors for each.

I'm sure there is a simple way to do this with VBA but any other sort of answers are also welcome.

EDIT: While I do appreciate answers, one that allows me to keep the .doc files as .docs is preferred.

like image 313
Eugene M Avatar asked Oct 23 '08 14:10

Eugene M


1 Answers

This is not from 2007, but the idea should suit. This example changes any current highlight to the new default highlight (wdBrightGreen) and any green text to red.

Sub ChangeColor
Options.DefaultHighlightColorIndex = wdBrightGreen

    Selection.Find.ClearFormatting
    Selection.Find.Highlight = True
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorBrightGreen
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorRed
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
like image 197
Fionnuala Avatar answered Sep 19 '22 19:09

Fionnuala