Solved

word change text color to blue in words with all caps

Posted on 2014-01-08
3
489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

717 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