Color Change Macro

W

Wynn

I wrote this simple working macro, but when I try to use it on certain
documents already created it isnt working. I have tried a number of
different experiments (like pasting the text into new word docs or purging
format in notepad then resetting the font color), but it will not change the
color of the text in these documents. The macro works fine in new docs that
I create - am I missing something?

Sub BlueColorChange()
'
' Macro to change standard blues to specific gradients
Selection.WholeStory
If Selection.Font.Color = RGB(0, 0, 128) Then
Selection.Font.Color = RGB(0, 45, 98)
End If
End Sub
 
J

Jonathan West

Hi Wynn,

If there is a single character in the selection that is not the same color
as the rest, Selection.Font.Color with return wdUndefined.

Now, what are you trying to achieve. Is it

1. Changing the whole document to your new color, irrespective of what color
the text was before, or
2. Changing just the text that is RGB(0, 0, 128) to RGB(0, 45, 98), and
leaving the rest alone?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
W

Wynn

Thanks, Jonathan. That would explain it. I am trying to change any text in
only that color to the new shade. When I have text with two different colors
(i.e. blue and black) I want to change the blue to a slightly different shade.

"Jonathan West" escribió:
 
J

Jonathan West

Wynn said:
Thanks, Jonathan. That would explain it. I am trying to change any text
in
only that color to the new shade. When I have text with two different
colors
(i.e. blue and black) I want to change the blue to a slightly different
shade.

Hi Wynn,

In that case, what you need to do is Find the blue text, and Replace it with
the different color. You can in fact do this without a macro. Go to Edit,
Replace. Click the More button to show the bottom part of the dialog.
Positoon the cursor in the "Find What" box, and then click Format, Font, and
set the color to the current shade of blue. Then position the cursor in the
Replace With box and click Format, Font, and set the color to the new shade
of blue. Then click Replace All.

The following macro achieves the same effect without you having to open the
dialog

Sub ReplaceBlueText()
With ActiveDocument.Range.Find
.Format = True
.Text = ""
.Font.Color = RGB(0, 0, 128)
.Replacement.Text = ""
.Replacement.Font.Color = RGB(0, 45, 98)
.Execute Replace:=wdReplaceAll
End With
End Sub


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top