tags:

views:

3012

answers:

3

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. So, that sort of answer is what will be marked as accepted.

A: 

You can always save the file as HTML, and replace colors there. Color is represented with

<span style='color:red'>...

and highlight is

<span style='background:yellow;mso-highlight:yellow'>...

Should be easy to manipulate if your document is simple enough.

Edit that answers the edit in the question: After you are done, re-open the file and save the file back as .doc.

buti-oxa
+1  A: 

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
Remou
A: 

This should work for your purpose:

Sub RehiliteAll()

    Const YOUR_REQUIRED_COLOR_IDX As Integer = 6 'RED'
    Dim doc As Range
    Set doc = ActiveDocument.Range

    With doc.Find
        .ClearFormatting 'resets default search options'
        .Highlight = True
        .Wrap = wdFindStop

        While .Execute

            If doc.HighlightColorIndex = YOUR_REQUIRED_COLOR_IDX Then
                doc.Select
                MsgBox doc.HighlightColorIndex
                'Do stuff here'
            End If

            'doc has been reassigned to the matching'
            'range; we do this so word keeps searching'
            'forward'
            doc.Collapse wdCollapseEnd
        Wend
    End With

    Set doc = Nothing
End Sub

'I am closing comment quotes so that SO formatting'
'does not get messed up too much.'
guillermooo