Change Text Color

NiceMan331
NiceMan331 used Ask the Experts™
on
Hi
i have word document consist of around 100 pages
i would like to change the text color by code based on existing text color
for example :
if text color = red , change it to blue
if blue , change it to black

and also , to format specific texts has blue color to be italic
... etc

how i can do it
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018
Commented:
You would have to select the sections you want changed and make those sections a specific Style. Then you can change the colour of the Style or Font. Once done, this gives you most flexibility for current and later changes.

OR,  Select blocks of text using the Ctrl Key along with Select to select multiple blocks and set the colour each time you do this.
RaminTechnical Advisor

Commented:
You need a Macro.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

no matter what you select as a solution, be sure to change the blue to black BEFORE changing the red to blue, otherwise you will end up with black through the entire document (unless of course, that is the result you want)

Author

Commented:
I need a code or macro to change it , not manually plz
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Just use Find and Replace but instead of typing text to find, you select font colour
http://somup.com/cbf3qFVVl9
Colleen Kayter4D Assets
Commented:
Shaun is right and Paul has an excellent point. Make a list of the changes you want to make. If any of the current states are to be results for other text, make those changes first (e.g., the blue becomes black before the red becomes blue).

If you think you might need to do all these same formatting tricks on other documents, record a macro as you go through the search and destroy process.

Out of curiosity, are the current font colors the result of someone else reviewing the doc? All the red and blue sounds like tracked changes.
RaminTechnical Advisor

Commented:
This is a simple VBA code to convert all Red fonts in your file to Italic blue, you can change the color font depending on your need.

Sub ChangeColorWithReplace()   
    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorRed
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorBlue
    Selection.Find.Replacement.Font.Italic = True
With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Open in new window

Technical Advisor
Commented:
This one converts red font to Italic blue and Blue to normal black.

Sub ReplaceFontColor()
    
    Application.ScreenUpdating = False
    Dim d As Document: Set d = ActiveDocument
    For i = 1 To d.Characters.Count
        
        If d.Characters(i).Font.TextColor.RGB = RGB(255, 0, 0) Then
            d.Characters(i).Font.TextColor.RGB = RGB(0, 0, 255)
            d.Characters(i).Font.Italic = True
            DoEvents
        
        Else
              If d.Characters(i).Font.TextColor.RGB = RGB(0, 0, 255) Then
                 d.Characters(i).Font.TextColor.RGB = RGB(0, 0, 0)
                 DoEvents
                
              End If
        End If
        
      Application.ScreenUpdating = True
        
    Next
    
End Sub

Open in new window

Colleen Kayter4D Assets

Commented:
NiceMan331, you've asked 175 questions and have only accepted 3 answers. Could you offer us some feedback on the comments provided?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial