how to get ascii value of a symbols?

G

Guest

Hi All,
I'm looking for code to get the ascii value of a document symbol in
the net for the past 4 days and I'm afraid I might miss my deadline just
because of this small work. If you know how to get ascii value of sybol
please let me know. My code looks like this but it fails to bring actual
ascii value.
ActiveDocument.Bookmarks("xxxsymbol").Select
x= asc(selection.text)

but it doesnt bring actual ascii value of the symbol arrow (ascii 117)
instead it brings out 40.

any ideas?
 
J

Jezebel

chr(40) = (

At a guess, your bookmark refers to more than just your symbol -- Asc()
returns the value of the first character of the argument. Quick method:
select the character you're concerned with, then in the VBA immediate
window --

? asc(selection)
 
G

Guest

Hi Jezebel,
Thanks for quick reply. But its returning the same 40 only.
I opened new document and added arrow symbol only and placed a book mark and
used the following to get ascii value....but didnt work..

ActiveDocument.Bookmarks("rnet_777_en773").Select
Debug.Print Asc(Selection)
Debug.Print Asc(Selection.text)

any idea how to get symbol ascii value?
 
G

Greg Maxey

Jezebel,

I can confirm that:

? Asc(selection) returns 40 when ( is selected and when the right
pointing arrow symbol inserted using Insert>Symbol>Symbols>Font
"Symbol" is selected.
 
G

Greg Maxey

In fact 40 must be a popular number. If I insert any of the five arrow
symbols Up, Down, Right, Left, and Right/Left, select it and run the
following code the inserted text is a "("

Sub Test()
Dim pAsc As Long
pAsc = Asc(Selection)
Selection.Range.InsertAfter Chr(pAsc)
End Sub

Rama, I realize that I am not answering yor question, and hopefully
Jezebel can.
 
J

Jay Freedman

This has been a problem since at least Word 6.0 and maybe earlier.

When you already know the symbol you want, such as the arrow, you can use
the FindSymbol macro in the Macros9.dot template or the FindSymbols macro in
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm (which also has a
link to download Macros9.dot if you don't have it).

The problem is this: When you insert a symbol from the Insert > Symbols
dialog and it's in a font different from the surrounding text -- for
example, inserting a Wingdings character into Times New Roman -- you don't
want the next regular character you type to be in Wingdings as if you had
changed the font. To avoid that, Word "wraps" the symbol in a special holder
that adopts the font of the surrounding text but contains the symbol and its
font. (It's similar to using an explicit {Symbol} field, but there's no
field there to expand.)

The stupid part is that the wrapper always returns an ASCII value of 40,
which is the same value as a parenthesis. This mistake has been around so
long that the Microsoft Word developers are afraid to change it, for fear of
breaking third-party software.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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