Link to home
Start Free TrialLog in
Avatar of gwarcher
gwarcher

asked on

word change text color to blue in words with all caps

I don't work in Word VBA so I am having trouble.

I have a large document whereby I am trying to iterate through the document and find all words that are in all caps format and change the font color to blue.  I have tried a couple for each loops but nothing I can find will stick.

This is simple and not working.

Public Sub AllCapsToBlue()

  Dim doc As Document

   Set doc = ActiveDocument
   
 For Each eword In doc.Range.Words
   
      If eword.Font.AllCaps = True Then
     
       eword.Font.ColorIndex = wdDarkBlue
           
   End If
   
 Next eword
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gwarcher
gwarcher

ASKER

perfect, thanks!
This can be done without a macro by specifying the font formatting, but here is a macro version:
Sub BlueCaps()
    With ActiveDocument.Range.Find
        .Font.AllCaps = True
        .Replacement.Font.Color = wdColorBlue
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window