How to read symbols from a DOC documents!

C

chenfeng

Using function "InsertSymbol", I can insert a symbol into a document. But
how can I read a symbol from a document?
Using "Characters(i).range.text", I can read a char. But when meeting a
symbol, the value of "Characters(i).range.text" is always '('.How can I get
the CharacterNumber of the symbol.
Waitting for help.
Thanks in advance!
 
M

macropod

Hi,

You might try something like:

Sub CharID()
MsgBox "Selected character is " & AscW(Selection.Text)
End Sub

for the Unicode value.

Bear in mind though that the same character value can display differently,
depending on the font.

Cheers
 
C

chenfeng

I tried the idea, but it does not work. Is there another solution idea?
I look through the "VBAWord9.hlp", but failed to get some related
information .
 
M

macropod

Hi chenfeng,

In your routine,
AscW(Selection.Characters(i).Text)
should return the character number for any character in the string.

Cheers
 
C

chenfeng

First thanks for your help! But I am sorry to say the following:
I input a symbol(¡ì¡°¡±) as the first character in a document and then
read the document with the following code :
MsgBox "First character is " &
AscW(oWordDoc.Paragraphs(1).Range.Characters.Item(1).Text)
When I input every symbol as the first character, the running result is
the same message: "First character is 40".
In another way, I use the following code to read the font name of the
character, and the result message is "Times New Roman", but not "Symbol":
MsgBox "The font name of first character is " &
oWordDoc.Paragraphs(1).Range.Characters.Item(1).Font.Name
So I think the reading of symbols in a document will need another better
solution.
Can someone help me?
 
M

macropod

Hi chenfeng,

In your original post, you asked: How can I get the CharacterNumber of the
symbol.

That is what code I provided does - it gives you the character's number.
Your string '(¡ì¡°¡±)' starts of with '(', the value of which is 40. You can
demonstrate that by typing '040' while holding down the Alt key, then
releasing the Alt key.

Cheers
 
C

chenfeng

My question is : How can I get the CharacterNumber of the symbol.
I use the following code to get the CharacterNumber of the selected
character:
-----------------------------code----------------------------------------
MsgBox "Selected character is " & AscW(Selection.Text)
MsgBOx "The font name of the selected character is "& Selection.Font.Name
-----------------------------code----------------------------------------
But when selecting a symbol, the running result is always the same
message:
"Selected character is 40. The font name of the selected character is Times
New Roman, which is the default font name."
"40" is not the correct CharacterNumber, and font name is not the correct
font name. The correct font name should be "Symbol". So I think the code
"AscW(Selection.Text)" does not work towards symbol.
Waitting for your help.
With Kind Regards.
 
K

Klaus Linke

Hi chenfeng,

Word protects symbols from symbol fonts if you insert them from the "Insert
Symbol" dialog.

This is done so they aren't changed when you change the font or style. But
it also results in Word reporting AscW( ) = 40 on all of them.

I've posted a macro to "unprotect" them (or to protect them again if you
want) ... just today again in

Newsgroups: microsoft.public.word.vba.customization
Subject: Symbol Characters
Date: Mon, 3 May 2004 11:00:46 -0700
Message-ID: <[email protected]>

It isn't archived on Google yet, but tomorrow you should be able to simply
copy the message ID into http://www.google.com/advanced_group_search.

Regards,
Klaus
 

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