Wingdings font returns ??? text

A

An Hong Phan

Hello,

I'm trying to get Text from Word doc by calling

Range.Text

Most of the time it returns the right string, however, For Wingdings font,
all I get out of it is a series of "?????"

How do I get the text or character codes for Wingdings text?

Thanks.
 
K

Klaus Linke

Hi,

Word uses the "private area" Unicode block starting at U+F000 for symbol
fonts.

The text doesn't actually consist of question marks -- You only get "?"
because neither the VBA editor nor Message boxes can deal with Unicode.

If you have some string with symbols in it and want to have the characters
as you typed them in on the keyboard (= map the codes to the 1-byte codes
below 256 that were used in pre-Unicode times), you could use something like

Dim i As Long
Dim myString As String
myString = Selection.Text
For i = 1 To Len(myString)
Select Case AscW(Mid(myString, i, 1))
Case &HF000 To &HF0FF
Mid(myString, i, 1) = _
ChrW(AscW(Mid(myString, i, 1)) - &HF000)
End Select
Next i
MsgBox myString

Or you can get the code of some selected symbol with
? AscW(Selection.Text) And &HFFFF&

(... the "And &HFFFF&" is needed because AscW returns a signed integer, and
you get negative numbers between &H7FFF and &HFFFF, so you convert it to a
Long variable with 4 bytes instead of 2, and mask the upper 2 bytes)

Or if you prefer a string with the hex number:
? Hex(AscW(Selection.Text))

Regards,
Klaus
 
A

An Hong Phan

Thank you very much!!! That's exactly what I'd need to do.
You saved my day.
Thanks,

- An H. Phan -
 

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