Inserting checkbox symbols using code

C

Charles Kenyon

I've been trying to figure out a code equivalent to the use of AutoText
entries in inserting checkbox macrobutton fields. A key problem is how to
test for what the current character is before switching it.

The following code ...

Sub Test()
Dim myASCII As String
myASCII = Asc(Selection.Text)
MsgBox myASCII
End Sub

.... reports a value of 40 for both a checked an an unchecked box.

The following code will insert a checked box:

Sub Test2()
Selection.Range.Font.Name = "Wingdings"
Selection.Range.Text = Chr$(254)
End Sub

The number for the unchecked box is 168.

Both of these are decimal codes from the Wingdings font.

I don't know of unicode symbols that will insert equivalent symbols, nor can
I figure out how to test for a Wingdings font code.

Any thoughts would be appreciated.

Once I get this, I have to code to insert the macrobuttons with that text.
Looking forward to it!

TIA
--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

JGM

Hi Charles,

I fiddled around with the Asc and Chr functions and came up with the
following little procedures that worked on my system (Windows and Word XP):

'_______________________________________
Sub Test_Unicode()

Dim Checked As Long
Dim Unchecked As Long

Selection.TypeParagraph
Selection.TypeParagraph
Selection.MoveLeft wdCharacter, 1, wdExtend
Selection.Range.Font.Name = "Wingdings"
Selection.MoveLeft wdCharacter, 1
Selection.TypeText ChrW(-3842)
Selection.TypeText " "
Selection.TypeText ChrW(-3928)

Selection.HomeKey wdLine

Selection.MoveRight wdCharacter, 1, wdExtend
Checked = AscW(Selection.Range.Text)

Selection.MoveRight wdCharacter, 2

Selection.MoveRight wdCharacter, 1, wdExtend
Unchecked = AscW(Selection.Range.Text)

Selection.HomeKey wdLine

MsgBox "The checked character's Unicode value is: " _
& Checked & " and the unchecked one is: " & _
Unchecked & ".", vbInformation, "Results"

End Sub
'_______________________________________

With unicode you can work with the Wingding font to read the character
unicode value.

'_______________________________________
Sub Test_ASC()

Dim Checked As Long
Dim Unchecked As Long

Selection.TypeParagraph
Selection.TypeParagraph
Selection.MoveLeft wdCharacter, 1, wdExtend
Selection.Range.Font.Name = "Wingdings"
Selection.MoveLeft wdCharacter, 1
Selection.TypeText Chr(254)
Selection.TypeText " "
Selection.TypeText Chr(168)

Selection.HomeKey wdLine

Selection.MoveRight wdCharacter, 1, wdExtend
Selection.Range.Font.Name = "Arial"
Checked = Asc(Selection.Range.Text)
Selection.Range.Font.Name = "Wingdings"

Selection.MoveRight wdCharacter, 2

Selection.MoveRight wdCharacter, 1, wdExtend
Selection.Range.Font.Name = "Arial"
Unchecked = Asc(Selection.Range.Text)
Selection.Range.Font.Name = "Wingdings"

Selection.HomeKey wdLine

MsgBox "The checked character's ASCII code is: " _
& Checked & " and the unchecked one is: " & _
Unchecked & ".", vbInformation, "Results"

End Sub
'_______________________________________

With ASCII you cannot work with the Wingdings font to read the character's
ASCII value.

Can someone explain the difference? (i.e. why unicode works with the
Wingdings font, but not ASCII, which returns 63 - Charles got 40, I got
63...go figure! - as a value for both checked and unchecked boxes).
Is Wingdings a "true" unicode font?
Why can't Wingdings return a different value for each character?

HTH Charles,
Cheers!
 
C

Charles Kenyon

Thank you for the start. I'll play with it.
--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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

Top