How to set the character set when adding text in VBA

A

Alan Silver

Hello,

I am trying to write a VB program (or VBA macro) that will print a
sample of every Hebrew font on my system. I have some VB code that
enumerates fonts, and when it finds a Hewbre one, it adds a couple of
lines to a Word doc showing the font name and some sample characters.

The problem is that the sample text is not showing correctly. Instead of
showing in Hebrew, it shows as boxes, squiggles, etc. I suspect (but
could be way wrong here) that this is because Word does not know what
character set to use, so uses the default, which gives the funny
characters.

Anyone any idea how to fix this ? The code looks like ...

With objWordDoc.Range
.Start = .End ' get to the end of the text
.Text = strFontName ' add a line with the name of the font
.Font = "Arial"
.LanguageID = WDEnglishUK

.Start = .End
.Text = "sample text" ' really uses Hebrew chars
.Font = strFontName
.LanguageID = WDHebrew
End With

The second call to .Text actually passes a string that contains the
Hebrew alphabet, but as that is in the upper art of the ASCII set, I
replaced it here so that it would pass through the e-mail servers (that
sometimes have trouble with anything above character 127).

Anyway, anyone know why the above doesn't work ? I can copy and paste
from a Hebrew word processor and the text displays fine. I would like to
be able to do this programmatically as I have a lot of fonts here and
would like to list them all.

Thanx in advance for any help.
 

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