Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


word change text color to blue in words with all caps

Posted on 2014-01-08
Medium Priority
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
Question by:gwarcher
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
LVL 53

Accepted Solution

Rgonzo1971 earned 2000 total points
ID: 39765895

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


Author Closing Comment

ID: 39765926
perfect, thanks!
LVL 76

Expert Comment

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


Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 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