BBO Discussion Forums: Inserting Color Suit Symbols in Word - BBO Discussion Forums

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Inserting Color Suit Symbols in Word VBA Code

#1 User is offline   Echognome 

  • Deipnosophist
  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 4,386
  • Joined: 2005-March-22

Posted 2010-February-28, 14:35

I am trying to update some system notes and trying to insert color suit symbols in my document. I can think of two ways to do this efficiently and wondered what other people have done.

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?
"Half the people you know are below average." - Steven Wright
0

#2 User is offline   Cascade 

  • PipPipPipPipPipPipPipPip
  • Group: Yellows
  • Posts: 6,760
  • Joined: 2003-July-22
  • Gender:Male
  • Location:New Zealand
  • Interests:Juggling, Unicycling

Posted 2010-February-28, 15:14

I use autocorrect with !c !d !h !s respectively.

Autocorrect allows you to correct to formated text. So I have my diamond and heart symbols formated to red coloured text.
Wayne Burrows

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 User is offline   Echognome 

  • Deipnosophist
  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 4,386
  • Joined: 2005-March-22

Posted 2010-February-28, 16:16

Cascade, on Feb 28 2010, 01:14 PM, said:

I use autocorrect with !c !d !h !s respectively.

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?
"Half the people you know are below average." - Steven Wright
0

#4 User is offline   Cascade 

  • PipPipPipPipPipPipPipPip
  • Group: Yellows
  • Posts: 6,760
  • Joined: 2003-July-22
  • Gender:Male
  • Location:New Zealand
  • Interests:Juggling, Unicycling

Posted 2010-February-28, 16:29

I colour the symbol in word then select it then go to autotext and create the autotext entry. The diamond and heart symbol are automatically displayed in autotext when they are selected in word. When I select formatted text the diamond and heart symbols turn red as the selected text is already red in word.
Wayne Burrows

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 User is offline   Echognome 

  • Deipnosophist
  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 4,386
  • Joined: 2005-March-22

Posted 2010-February-28, 17:08

Great. Got it to work. Thanks.

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.
"Half the people you know are below average." - Steven Wright
0

#6 User is offline   JanM 

  • PipPipPipPipPip
  • Group: Full Members
  • Posts: 737
  • Joined: 2006-January-31

Posted 2010-February-28, 17:39

Slightly off this topic, but also about suit symbols and Word and maybe someone here will be able to solve my problem (which I've given up on - I'm not using Word for bridge notes any more). When I upgraded to the latest version of Word, it decided not to recognize suit symbols any more. If I opened an old document (or someone else's) with suits symbols in it, I got open boxes <grrr>. If I try to do "insert" and put in a suit symbol, it looks as if I should be able to (there's a chart that has suit symbols on it) but when I click on one and then on "insert, even in Times New Roman, which should have suit symbols, I get a box instead of the suit symbol. I have uninstalled and reinstalled Word, tried to point it to the Times New Roman that does suit symbols just fine in Pages (guess I should "confess" that all of this is on a Mac :)). Nothing works. The only way I can read a Word document that has suit symbols is to open it in Pages, where the suit symbols are fine but sometimes the formatting isn't.

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 Martel, who should probably state that she is not speaking on behalf of the USBF, the ACBL, the WBF Systems Committee, or any member of any Systems Committee or Laws Commission.
0

#7 User is offline   Echognome 

  • Deipnosophist
  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 4,386
  • Joined: 2005-March-22

Posted 2010-February-28, 18:16

JanM, on Feb 28 2010, 03:39 PM, said:

Slightly off this topic, but also about suit symbols and Word and maybe someone here will be able to solve my problem (which I've given up on - I'm not using Word for bridge notes any more). When I upgraded to the latest version of Word, it decided not to recognize suit symbols any more. If I opened an old document (or someone else's) with suits symbols in it, I got open boxes <grrr>. If I try to do "insert" and put in a suit symbol, it looks as if I should be able to (there's a chart that has suit symbols on it) but when I click on one and then on "insert, even in Times New Roman, which should have suit symbols, I get a box instead of the suit symbol. I have uninstalled and reinstalled Word, tried to point it to the Times New Roman that does suit symbols just fine in Pages (guess I should "confess" that all of this is on a Mac :)). Nothing works. The only way I can read a Word document that has suit symbols is to open it in Pages, where the suit symbols are fine but sometimes the formatting isn't.

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.
"Half the people you know are below average." - Steven Wright
0

#8 User is offline   blackshoe 

  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 17,562
  • Joined: 2006-April-17
  • Gender:Male
  • Location:Rochester, NY

Posted 2010-February-28, 18:36

Try OpenOffice, or NeoOffice on Mac, which has a nice Mac interface (OpenOffice uses the XWindows interface from Unix, I think). The symbols are there, certainly (though I don't know about in color). I haven't tried to work out how to do it, but I'd start by looking at the "Autocorrect..." function, in the tools menu.
--------------------
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
0

#9 User is offline   TimG 

  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 3,972
  • Joined: 2004-July-25
  • Gender:Male
  • Location:Maine, USA

Posted 2010-February-28, 21:42

I like your autocorrect solution.

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?
0

#10 User is offline   Echognome 

  • Deipnosophist
  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 4,386
  • Joined: 2005-March-22

Posted 2010-February-28, 22:55

Tim,

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.
"Half the people you know are below average." - Steven Wright
0

#11 User is offline   Cascade 

  • PipPipPipPipPipPipPipPip
  • Group: Yellows
  • Posts: 6,760
  • Joined: 2003-July-22
  • Gender:Male
  • Location:New Zealand
  • Interests:Juggling, Unicycling

Posted 2010-February-28, 22:58

Tim

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.
Wayne Burrows

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 User is offline   Rossoneri 

  • Wabbit
  • PipPipPipPipPip
  • Group: Full Members
  • Posts: 974
  • Joined: 2007-January-13
  • Gender:Male
  • Location:Singapore

Posted 2010-March-01, 03:28

Above reasons are probably why I'm more willing to use LaTeX instead of Word...
SCBA National TD, EBU Club TD

Unless explicitly stated, none of my views here can be taken to represent SCBA or any other organizations.
0

#13 User is offline   Tryggolaf 

  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 2014-January-08

Posted 2014-June-07, 10:33

 Echognome, on 2010-February-28, 17:08, said:

Great. Got it to work. Thanks.

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?
0

#14 User is offline   fromageGB 

  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 2,679
  • Joined: 2008-April-06

Posted 2014-June-07, 11:45

Rather than use an additional character when writing, such as having to type 3!h for example, I find it easiest to have 3h and the other 27 combinations put separately into autocorrect. Now I can just type 1s 2c etc as normal, and it comes out in colour as 1 2. (Libreoffice, but I'm sure it would be the same in word.)
0

#15 User is offline   Cascade 

  • PipPipPipPipPipPipPipPip
  • Group: Yellows
  • Posts: 6,760
  • Joined: 2003-July-22
  • Gender:Male
  • Location:New Zealand
  • Interests:Juggling, Unicycling

Posted 2014-June-07, 21:19

 fromageGB, on 2014-June-07, 11:45, said:

Rather than use an additional character when writing, such as having to type 3!h for example, I find it easiest to have 3h and the other 27 combinations put separately into autocorrect. Now I can just type 1s 2c etc as normal, and it comes out in colour as 1 2. (Libreoffice, but I'm sure it would be the same in word.)


If you want to write about play then you will need 52 more or standalone s h d c autocorrects.
Wayne Burrows

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 User is offline   Cascade 

  • PipPipPipPipPipPipPipPip
  • Group: Yellows
  • Posts: 6,760
  • Joined: 2003-July-22
  • Gender:Male
  • Location:New Zealand
  • Interests:Juggling, Unicycling

Posted 2014-June-07, 21:47

 Tryggolaf, on 2014-June-07, 10:33, said:

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?


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.
Wayne Burrows

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 User is offline   fromageGB 

  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 2,679
  • Joined: 2008-April-06

Posted 2014-June-08, 05:11

 Cascade, on 2014-June-07, 21:47, said:

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.

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.
0

#18 User is offline   fromageGB 

  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 2,679
  • Joined: 2008-April-06

Posted 2014-June-08, 05:53

I have now recorded a libreoffice macro so that I can type something like "bid 3;h and lead the ;c5" and then when the document is completed just run the one macro to convert everything to coloured suit symbols, but I find I don't like this approach. I like the suit symbols and colours to appear as I type, because it is much clearer to read as you are composing.
0

#19 User is offline   fromageGB 

  • PipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 2,679
  • Joined: 2008-April-06

Posted 2014-June-08, 06:52

I have tried echognome's idea of assigning a macro for each coloured symbol to a key, and this is clean as it works with any trailing or leading characters, but I cannot assign them to useful keys. For example, as my keyboard has function keys in groups of four, it would be good to assign F1=spades, F2=hearts, F3=diamonds, F4=clubs. However, while I can do this for F2/3/4 I cannot reassign F1 from its meaning of "help". Similarly there is a reserved key in each of the other blocks of four. While I could use shift in conjunction with an F key, this is not convenient, and I'll stick to my 28 autocorrects.
0

#20 User is offline   nige1 

  • 5-level belongs to me
  • PipPipPipPipPipPipPipPipPip
  • Group: Advanced Members
  • Posts: 9,128
  • Joined: 2004-August-30
  • Gender:Male
  • Location:Glasgow Scotland
  • Interests:Poems Computers

Posted 2014-June-08, 07:19

 fromageGB, on 2014-June-08, 06:52, said:

I have tried echognome's idea of assigning a macro for each coloured symbol to a key, and this is clean as it works with any trailing or leading characters, but I cannot assign them to useful keys. For example, as my keyboard has function keys in groups of four, it would be good to assign F1=spades, F2=hearts, F3=diamonds, F4=clubs. However, while I can do this for F2/3/4 I cannot reassign F1 from its meaning of "help". Similarly there is a reserved key in each of the other blocks of four. While I could use shift in conjunction with an F key, this is not convenient, and I'll stick to my 28 autocorrects.
With macros similar to Echognome's. I associate
, , , 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.
0

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users