Macro to insert red heart (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 19, 2002
Messages
36,419
I am writing documents that require the suit symbols for clubs, diamonds, hearts, and spades and I would like the diamonds and hearts to be red.

My old macros no longer work so I created new ones. I couldn't get the macro recorder to control the color so I did it the hard way.
Code:
Sub Heart()
' Heart Macro'
'
    Selection.Font.Color = vbRed
    Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3927, Unicode:=True
    Selection.Font.Color = vbBlack
End Sub

The problem with this method is that not all text is black. The user may be using a themed color choice so a better solution would be to copy the current color and save it to a variable. Change the color to red, insert the symbol. Then change the color back to what it was originally.

I develop with Access so the Word object model mystifies me and so I rely on the macro recorder to record macros for me. But the macro recorder will not create code to manage the color changes.

Does anyone know the VBA to do this so I can update the macro?
Thanks
 

June7

AWF VIP
Local time
Today, 11:04
Joined
Mar 9, 2014
Messages
4,400
Consider:
Code:
    Debug.Print Selection.Font.Color
    lngColor = Selection.Font.Color
    Selection.Font.Color = RGB(20, 230, 0)
    Debug.Print Selection.Font.Color
    Selection.Font.Color = lngColor
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 19, 2002
Messages
36,419
Thanks, I'm sure that is a variation I tried but intellisense kept changing Color to ColorIndex and finally I let it.
 

June7

AWF VIP
Local time
Today, 11:04
Joined
Mar 9, 2014
Messages
4,400
Yes, I saw that and had to override. But if it works then go with it
 

Users who are viewing this thread

Top Bottom