Solved

word change text color to blue in words with all caps

Posted on 2014-01-08
3
475 Views
Last Modified: 2014-01-08
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
0
Comment
Question by:gwarcher
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39765895
Hi,

Maybe what you want is to change in blue all the capitalized words

and not the ones with the Format AllCaps

pls try

Public Sub AllCapsToBlue()

Dim doc As Document
Set doc = ActiveDocument

For Each eword In doc.Range.Words
    If eword.Text = UCase(eword.Text) Then
        eword.Font.ColorIndex = wdDarkBlue
    End If
Next eword
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:gwarcher
ID: 39765926
perfect, thanks!
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39765936
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

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
My experience with Windows 10 over a one year period and suggestions for smooth operation
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question