?
Solved

word change text color to blue in words with all caps

Posted on 2014-01-08
3
Medium Priority
?
497 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 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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 Admins - 7 Day Trial

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

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…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

770 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