checking Font Color in a macro

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

Guest

If I have a macro in word where I change the font color [using shortcut keys
I made -- Alt-R and Alt-B -- from the:And from there just selecting Format in the Categories, and FontColor in the
Commands.


Anyway -- I'm not familiar enough with the objects to know how to do this
offhand, but I'm wondering if there's a way to check what the fontcolor is in
the macro, and if it's black I'll switch it to red, and if it's red I'll
switch it to black.

I was just hoping this could be done in a relatively simple IF statement,
and if there are any examples out there I can check out if anyone can guide
me in that direction, that'd be great.


Any thoughts anyone could spare would be appreciated.

Thanks again,

M
 
What the font color is where? Do you mean the selected text? Then
perhaps something like:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = Selection.Range
Select Case oRng.Font.Color
Case wdColorRed
oRng.Font.Color = wdColorAutomatic
Case wdColorAutomatic
oRng.Font.Color = wdColorRed
Case Else
'Do nothing or do whatever
End Select
End Sub



If I have a macro in word where I change the font color [using shortcut keys
I made -- Alt-R and Alt-B -- from the:And from there just selecting Format in the Categories, and FontColor in the
Commands.


Anyway -- I'm not familiar enough with the objects to know how to do this
offhand, but I'm wondering if there's a way to check what the fontcolor is in
the macro, and if it's black I'll switch it to red, and if it's red I'll
switch it to black.

I was just hoping this could be done in a relatively simple IF statement,
and if there are any examples out there I can check out if anyone can guide
me in that direction, that'd be great.


Any thoughts anyone could spare would be appreciated.

Thanks again,

M
 
Sorry -- yes, I meant the selected text, and that's what I was looking for
[the case statement makes more sense].

thanks.

Greg Maxey said:
What the font color is where? Do you mean the selected text? Then
perhaps something like:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = Selection.Range
Select Case oRng.Font.Color
Case wdColorRed
oRng.Font.Color = wdColorAutomatic
Case wdColorAutomatic
oRng.Font.Color = wdColorRed
Case Else
'Do nothing or do whatever
End Select
End Sub



If I have a macro in word where I change the font color [using shortcut keys
I made -- Alt-R and Alt-B -- from the:
Tools >> Customize Menu; Then selecting >> Commands then >> Keyboard .
And from there just selecting Format in the Categories, and FontColor in the
Commands.


Anyway -- I'm not familiar enough with the objects to know how to do this
offhand, but I'm wondering if there's a way to check what the fontcolor is in
the macro, and if it's black I'll switch it to red, and if it's red I'll
switch it to black.

I was just hoping this could be done in a relatively simple IF statement,
and if there are any examples out there I can check out if anyone can guide
me in that direction, that'd be great.


Any thoughts anyone could spare would be appreciated.

Thanks again,

M
 

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

Similar Threads


Back
Top