Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a text content in MS Office Word 2007.
Assume something like the following : Abcd Efgh .....

Now I wanna change the color of each A in the content to red.
How can I do it in MS Office Word 2007 ?

share|improve this question
1  
May want to clarify this question/answer by renaming it to something like: How do I change the font color of a specific letter throughout the entire Microsoft Word document? –  Kerry Jan 8 '11 at 19:34
    
@Kerry: Thanks, I'll do it? –  Mohammad Jan 9 '11 at 14:38
add comment

2 Answers

up vote 3 down vote accepted

Easier way would be use Find and Replace and use the Advanced Options where you can format the font type, color and size and make sure to uncheck "Ignore Case" so you only get the "A" instead of all instances of "a" or "A".

share|improve this answer
    
Yes, this approach is easier! Nice! I was not aware of that additional Find and Replace functionality in Word, impressive. Your answer seems to be the most straighforward solution to the orignial question/problem with my code-based approach maybe being the start of something to use for more complex needs that the Find/Replace dialog doesn't support yet. –  Kerry Jan 9 '11 at 17:16
    
Thanks dude, the way that you've posted it, is very clear and easy ;-) –  Mohammad Feb 16 '11 at 13:39
add comment

Assuming you do not want to do this manually I beleive the primary way to automate this is to use Word's built-in Visual Basic for Applications programming language and write the script/code to search for the capital letter A and change its color.

Here is one way to do this by putting the code in the active Word Document. I tried this in Word 2010 so I am not 100% that it will work the same in Word 2007 but it probably will.

You have to enable Marcos for this code to run.

So In Word go to File Save As and choose "Word Macro-Enabled Document".

You then need to be able to use the Developer tools in Word so right-click on your ribbon bar and choose "Customize the Ribbon":

alt text

And Put a checkmark next to "Developer" and click "OK".

alt text

In the Word Document that you want to perform this magic in (the one you saved as a Macro-Enabled Word document) click on the newly visible Developer Tab and click on the "Visual Basic" button to open Visual Basic.

alt text

Visual Basic for Applications will open up. Under "Microsoft Word Object" double-click "ThisDocument" to add some code to this Word document.

alt text

In the Window that opens up, paste in the following Visual Basic Code:

Sub ChangeLetterColor()

' Enter the exact letter you want to globally search for in ThisDocument
' Case matters, "A" is not the same as "a"

Const LETTER_TO_CHANGE = "A"

' Enter one of the Word color Constant names to determine the color to change the letter to
' Example Word color constants are:
' wdBlack
' wdBlue
' wdBrightGreen
' wdDarkBlue
' wdDarkRed
' wdDarkYellow
' wdGray25
' wdGray50
' wdGreen
' wdPink
' wdRed
' wdTeal
' wdTurquoise
' wdViolet
' wdWhite
' wdYellow

Const COLOR_TO_CHANGE_TO = wdRed


For i = 1 To ThisDocument.Range.Characters.Count
    If ThisDocument.Range.Characters(i) = LETTER_TO_CHANGE Then
        ThisDocument.Range.Characters(i).Font.ColorIndex = COLOR_TO_CHANGE_TO
    End If
Next

End Sub

Now, click on the "Run" button on the VBA Toolbar and switch back to your Word Document. The letter defined in the script should now have its font color changed.

alt text


Here are other sample scripts with similar goals. You can refer to them for more details.

http://stackoverflow.com/questions/2396825/how-can-i-loop-through-every-letter-in-ms-word-using-vba

http://blogs.technet.com/b/heyscriptingguy/archive/2006/07/14/how-can-i-search-for-and-reformat-highlighted-text-in-a-word-document.aspx

share|improve this answer
    
If unsure as to a specific command to use, one can simply record a dummy macro, and cut and paste the code. Just select Tools->Macro->Record New Macro, perform the operations required, stop recording, and then cut and paste the resulting code! Read more at Suite101 –  Ivo Flipse Jan 8 '11 at 18:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.