replace font color

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Word 2003

What I have is a rather lengthy document within which some of the font
colors are other than Black.

What I would like to do is come up with a macro that in essence finds any
font that is NOT Black and change it to Black.

It is my understanding that this can most probably be done with a
find/replace using Wild Cards, but in furthering my VBA education, I would
like to know how it could be done with a VBA Macro.

Thanks in advance - Rod
 
Hi Rod,

You could use Ctrl-A to select the whole document, then click on the font colour icon on the toolbar (or the font attributes via the
menu) and set the colour to black or auto.

Cheers
 
Hey Macropod.

I appreciate you taking the time to respond. However, there are some
instances where I do not want the font color to be changed to Black and to
remain whatever color it may currently be. I would like a macro whereby I
could selectively pick the color(s) that I would like to have changed to
Black.

I would like to be able to do it via macro, as I am embarking on the VBA
learning process and would like to use the resulting macro as a "real world"
learning tool, applicable to my given situation.

With much appreciation - Rod


macropod said:
Hi Rod,

You could use Ctrl-A to select the whole document, then click on the font colour icon on the toolbar (or the font attributes via the
menu) and set the colour to black or auto.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

RPMitchal said:
Word 2003

What I have is a rather lengthy document within which some of the font
colors are other than Black.

What I would like to do is come up with a macro that in essence finds any
font that is NOT Black and change it to Black.

It is my understanding that this can most probably be done with a
find/replace using Wild Cards, but in furthering my VBA education, I would
like to know how it could be done with a VBA Macro.

Thanks in advance - Rod
 
Cheers Macropod:

I tried using the below to accomplish my goal, but received an error on the
line which reads:

.Font.Color <> RGB(0, 0, 128)

I was unable to figure out (as of yet) what I am missing to cause the error.
Perhaps you can assist with the below coding.

Thanks Again - Rod

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

macropod said:
Hi Rod,

You could use Ctrl-A to select the whole document, then click on the font colour icon on the toolbar (or the font attributes via the
menu) and set the colour to black or auto.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

RPMitchal said:
Word 2003

What I have is a rather lengthy document within which some of the font
colors are other than Black.

What I would like to do is come up with a macro that in essence finds any
font that is NOT Black and change it to Black.

It is my understanding that this can most probably be done with a
find/replace using Wild Cards, but in furthering my VBA education, I would
like to know how it could be done with a VBA Macro.

Thanks in advance - Rod
 
I don't know how to do it via VBA, but it's a simple Find/Replace (not even
requiring wildcards) to do manually. Just select Font: Color: Whatever in
the "Find what" box and "Font: Color: Black" in the "Replace with" box,
leaving both boxes empty.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Hi Rod,

My response was based on your problem descriptions, which included "finds any font that is NOT Black and change it to Black".

As for a macro, try selecting a coloured word(s) then using the macro recorder to capture your actions as you change the font
colour. Although the code will be unnecessarily verbose, the macro recorder does help you to work out what vba commands you might to
build your own routines. In this case, if only acting on a selected range is what you want, stripping the recorded macro down to the
bare essentials may be all that you need.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

RPMitchal said:
Hey Macropod.

I appreciate you taking the time to respond. However, there are some
instances where I do not want the font color to be changed to Black and to
remain whatever color it may currently be. I would like a macro whereby I
could selectively pick the color(s) that I would like to have changed to
Black.

I would like to be able to do it via macro, as I am embarking on the VBA
learning process and would like to use the resulting macro as a "real world"
learning tool, applicable to my given situation.

With much appreciation - Rod


macropod said:
Hi Rod,

You could use Ctrl-A to select the whole document, then click on the font colour icon on the toolbar (or the font attributes via
the
menu) and set the colour to black or auto.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

RPMitchal said:
Word 2003

What I have is a rather lengthy document within which some of the font
colors are other than Black.

What I would like to do is come up with a macro that in essence finds any
font that is NOT Black and change it to Black.

It is my understanding that this can most probably be done with a
find/replace using Wild Cards, but in furthering my VBA education, I would
like to know how it could be done with a VBA Macro.

Thanks in advance - Rod
 
Macropod and Suzanne:

Fortunately, I'm aware of your responsive solutions as to how to go about
this, outside of establishing a macro. I guess I've simply got it in my head
that I want to go about this situation via the use of a macro.

I have already completed this portion of my task by using a method (without
a macro) of replacing the colored fonts with Black.

However, I am committed to learning at least the basics of VBA and have been
attempting to write my own code for simple situations that I encounter in
order to get a handle on how VBA works. Which entails using these simple
situations as a way of putting macros together, examining the resulting code
and then referring to my collection of reference books and/or this forum for
additional insight if/when things go awry. With that in mind, I am going to
give Macropod's suggestion a "go" to see if I can work it out that way; using
the "recorder" and taking it from there.

As always, thanks so very much for being "out there" for those of us who
have come to depend upon you.

Happy Thanksgiving to you Suzanne. I know that you're a "Yank" because
you're right next door in Alabama. Atlanta here! :-)

Rod
 
I respect your desire to learn VBA, and your approach is a sound one. I keep
saying I'm going to do that someday "when I have time." <g>

I'm sure you're aware of the weaknesses of the Macro Recorder, but see
http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm for some advice
on "fixing" recorded macros.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Suzanne:

The best of luck to you on that score when you get around to it. Maybe one
day I'll be able to assist you with a dilemma or just answer a question you
may have.

Rod
 

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

Back
Top