Inserting Color Suit Symbols in Word VBA Code
#1
Posted 2010-February-28, 14:35
Method 1 - Record a Macro for inserting each suit symbol and assign a hotkey to each macro. Here's the code I wrote for this method:
Sub InsertClub()
Selection.Font.Color = wdColorGreen
Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3929, Unicode:=True
Selection.Font.Color = wdColorAutomatic
End Sub
Sub InsertDiamond()
Selection.Font.Color = wdColorOrange
Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3928, Unicode:=True
Selection.Font.Color = wdColorAutomatic
End Sub
Sub InsertHeart()
Selection.Font.Color = wdColorRed
Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3927, Unicode:=True
Selection.Font.Color = wdColorAutomatic
End Sub
Sub InsertSpade()
Selection.Font.Color = wdColorBlack
Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3926, Unicode:=True
Selection.Font.Color = wdColorAutomatic
End Sub
Method 2 - Use the AutoCorrect to insert the suit symbols and then write a macro to go through the entire document and replace all suit symbols with the same symbol but with the respective colors. The advantage of this method is you can use !c, !d, !h, and !s to edit the suit symbols in the document and then do one sweep at the end to attach the colors. The disadvantage is that it doesn't seem to work as I expect it to. Some of the symbols don't get converted and I don't understand why. Anyway, here is the code I have (mainly from recording and replacing code).
Sub SuitColors()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ChrW(9827)
.Replacement.Text = ChrW(9827)
.Replacement.Font.Color = wdColorGreen
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ChrW(9830)
.Replacement.Text = ChrW(9830)
.Replacement.Font.Color = wdColorOrange
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ChrW(9829)
.Replacement.Text = ChrW(9829)
.Replacement.Font.Color = wdColorRed
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ChrW(9824)
.Replacement.Text = ChrW(9824)
.Replacement.Font.Color = wdColorAutomatic
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Any thoughts from other people? What has been successful for you? Any other methods that may work better?
#2
Posted 2010-February-28, 15:14
Autocorrect allows you to correct to formated text. So I have my diamond and heart symbols formated to red coloured text.
I believe that the USA currently hold only the World Championship For People Who Still Bid Like Your Auntie Gladys - dburn
dunno how to play 4 card majors - JLOGIC
True but I know Standard American and what better reason could I have for playing Precision? - Hideous Hog
Bidding is an estimation of probabilities SJ Simon
#3
Posted 2010-February-28, 16:16
Cascade, on Feb 28 2010, 01:14 PM, said:
Autocorrect allows you to correct to formated text. So I have my diamond and heart symbols formated to red coloured text.
Wayne,
For some reason I'm having difficulty getting my AutoCorrect to do that. I can have it set to formatted text for the symbol, but I don't know how to change the text color. Any hints?
#4
Posted 2010-February-28, 16:29
I believe that the USA currently hold only the World Championship For People Who Still Bid Like Your Auntie Gladys - dburn
dunno how to play 4 card majors - JLOGIC
True but I know Standard American and what better reason could I have for playing Precision? - Hideous Hog
Bidding is an estimation of probabilities SJ Simon
#5
Posted 2010-February-28, 17:08
So to summarize for those that haven't done this. I did the following (easy) steps using Wayne's tips and it doesn't require any macros at all. Note that this was using Microsoft Word 2003. The steps may be different using another version of Word.
1. Go to the Insert menu and select Symbol..
2. Insert a Club, Diamond, Heart, and Spade symbol into your document and close the dialog box.
3. Highlight your club symbol. Select the font color you would like. I chose green, but you can leave as black if you like. While the symbol is highlighted, go to the Tools menu and select AutoCorrect Options...
4. Under the Replace box, I typed !c and the With box was already populated with my green club symbol. Hit the Add button.
5. Repeat steps 3 and 4 for the diamond, heart, and spade symbols.
Voila. Anytime you type !c, !d, !h, or !s you will have the colored symbol inserted into your document.
#6
Posted 2010-February-28, 17:39
I'm way too cheap to print notes in color, so I just use outline for the red suits, by the way - it works for me .
#7
Posted 2010-February-28, 18:16
JanM, on Feb 28 2010, 03:39 PM, said:
I'm way too cheap to print notes in color, so I just use outline for the red suits, by the way - it works for me .
Jan - My work recently switched over to 2007, but I have resisted as much as I can. In June, Office 2010 will come out and from what I've heard on the beta, it will be much better than 2007.
As for your particular problem, I'm not sure why the suit symbols aren't working. I believe the font I use for the card symbols is Symbol, not Times New Roman. I don't know if that will help you.
Good luck.
#8
Posted 2010-February-28, 18:36
As for tv, screw it. You aren't missing anything. -- Ken Berg
I have come to realise it is futile to expect or hope a regular club game will be run in accordance with the laws. -- Jillybean
#9
Posted 2010-February-28, 21:42
I have assigned alt-s to a spade symbol, alt-h to a heart symbol, alt-d to a diamond symbol and alt-c to a club symbol. But, so far as I know, there is no way to make sure the alt-d and alt-h automatically insert a red symbol. So, I have a macro that changes everything when I am done. Do you know if autocorrect can be used with the assigned alt keys to get red symbols?
I have noticed that when there are suit symbols in headings that are used for a table of contents entry that there is trouble with toc update. Have you encountered this?
#10
Posted 2010-February-28, 22:55
I think you can get the colors by using the Method 1 approach I list above and assigned your Alt keys to run the macros. That being said, I'm not sure if you can assign an Alt key or if it has to be a control key, which isn't as nice, since you won't want to replace your meanings for control C, Control D, Control H, and Control S! I think I used Ctrl-Alt-C, etc, but that's more keystrokes. The autocorrect way is really much simpler.
I have not used the automatic TOC generator from Word. Well, I have for work, but someone has already built it by the time I look at it.
#11
Posted 2010-February-28, 22:58
I am not sure about your heading and TOC issue.
If you have alt d and alt h assigned to diamond and heart symbols respectively then you can get these to be automatically coloured by adding two autotext entries that change any diamond to a formated red diamond and similarly with a heart.
Essentially use the steps above but instead of !d as the autotext trigger have a normal black diamond as the trigger converting it to a red diamond.
I believe that the USA currently hold only the World Championship For People Who Still Bid Like Your Auntie Gladys - dburn
dunno how to play 4 card majors - JLOGIC
True but I know Standard American and what better reason could I have for playing Precision? - Hideous Hog
Bidding is an estimation of probabilities SJ Simon
#12
Posted 2010-March-01, 03:28
Unless explicitly stated, none of my views here can be taken to represent SCBA or any other organizations.
#13
Posted 2014-June-07, 10:33
Echognome, on 2010-February-28, 17:08, said:
So to summarize for those that haven't done this. I did the following (easy) steps using Wayne's tips and it doesn't require any macros at all. Note that this was using Microsoft Word 2003. The steps may be different using another version of Word.
1. Go to the Insert menu and select Symbol..
2. Insert a Club, Diamond, Heart, and Spade symbol into your document and close the dialog box.
3. Highlight your club symbol. Select the font color you would like. I chose green, but you can leave as black if you like. While the symbol is highlighted, go to the Tools menu and select AutoCorrect Options...
4. Under the Replace box, I typed !c and the With box was already populated with my green club symbol. Hit the Add button.
5. Repeat steps 3 and 4 for the diamond, heart, and spade symbols.
Voila. Anytime you type !c, !d, !h, or !s you will have the colored symbol inserted into your document.
For some odd reason, after changing the font color of the hearts symbol to red and keeping the symbol highlighted while opening the AutoCorrect menu (File-Options-Proofing-AutoCorrect Options in Microsoft Word 2010) it still remains black. So the !H-command in Word gives me ♥ instead of ♥ and a related problem I encounter is all the text after the ♥-symbol automatically turning red as well. So it seems like I'm changing the color of the entire text and symbols instead of only the ♥-symbol. Does anyone know how I can fix this problem?
#14
Posted 2014-June-07, 11:45
#15
Posted 2014-June-07, 21:19
fromageGB, on 2014-June-07, 11:45, said:
If you want to write about play then you will need 52 more or standalone s h d c autocorrects.
I believe that the USA currently hold only the World Championship For People Who Still Bid Like Your Auntie Gladys - dburn
dunno how to play 4 card majors - JLOGIC
True but I know Standard American and what better reason could I have for playing Precision? - Hideous Hog
Bidding is an estimation of probabilities SJ Simon
#16
Posted 2014-June-07, 21:47
Tryggolaf, on 2014-June-07, 10:33, said:
In the autocorrect options there is a option for plain text or formatted text. Make sure you have selected formatted text.
What happens for me is that I select a green club symbol say. I go to the autocorrect options as you describe. I need to fill in the Replace field with !c say and to the right of that is a With field. The With field is initially populated with a black club symbol. Above that field is a radio button with the two options. The default is plain text. When I click the formatted text option the club symbol turns green corresponding to the colour of the text in my document.
This seems to work fine and I get !c replaced with my green club symbol. However there are a few quirks. The autocorrect works fine if I type !c followed by a space and !c followed by any punctuation symbol (well I haven't actually tried them all) but it does not seem to work if I follow with an alphanumeric character so !cs or !cx or !cA do not autocorrect.
The text after the symbol reverts to the default colour that I am using. However if I subsequently edit text by for example clicking immediately after the club symbol the subsequent text I write is in green.
I believe that the USA currently hold only the World Championship For People Who Still Bid Like Your Auntie Gladys - dburn
dunno how to play 4 card majors - JLOGIC
True but I know Standard American and what better reason could I have for playing Precision? - Hideous Hog
Bidding is an estimation of probabilities SJ Simon
#17
Posted 2014-June-08, 05:11
Cascade, on 2014-June-07, 21:47, said:
Libreoffice is the same. If I do want to write about about play, such as "play the ♥5" it comes out as "play the ;h5" (yes, I also have ;h for when there there is no preceding number, but use ; rather than ! as it saves using the shift key) so what I do is type "play the ;h 5" which appears as "play the ♥ 5" and then go back to delete the space.
I think to do this properly without 52 autocorrect entries would require a macro. I'll experiment.
If I follow the the to-be-replaced entry immediately by a punctuation character, interestingly the punctuation itself (as well as any subsequent character) reverts to the default writing colour. What we need is a keyboard with a non-spacing invisible punctuation character!
Incidentally, 3;h does not substitute, which is why I have the 28 autocorrects, as I use those frequently.
#18
Posted 2014-June-08, 05:53
#19
Posted 2014-June-08, 06:52
#20
Posted 2014-June-08, 07:19
fromageGB, on 2014-June-08, 06:52, said:
♠, ♥, ♦, and ♣ with
ALT/S, ALT/H, ALT/D and ALT/C, respectively.
There are enough free ALT keys for all my editing needs.
An advantage of defining macros for most repetitive editing tasks is that you can easily import your latest version into each computer on which you use Word.
When you leave, you can restore Word to the original state in which you found it.