international chars in VB for Word 2003

T

ToddInTR

Hello,

I would like to insert text into a Word document from a Word VB macro where
the text contains non-English characters. When I enter these characters in
the macro, they are displayed as garbage. When the macro is run, they are
transformed into yet other garbage characters. I played around w/ Regional
settings, etc. but have not been able to find a way. Any help will be most
appreciated.

Todd
 
K

Klaus Linke

Hi Todd,

The problem probably is that the VBA editor can't deal with the international characters (Unicode).
If you define strings in VBA, you'd need to use, say, ChrW(960) or ChrW(&H03C0) for the greek letter "pi".

If you read the strings from a Word document (say, str=Selection.Text), that is not a problem, because both Word and VBA can deal fine with Unicode.
Only the VBA editor (and for example MsgBox or user forms) can't yet.

You can change the whole VBA editor to another code page in "Tools > Options > Editor format > Font" or something like that (say, to Hebrew, Cyrillic or Greek), but that probably won't help you much, using an English version and an English keyboard.

Greetings,
Klaus
 
T

ToddInTR

Hi Klaus,

Many thanks for your answer. Since posting, I figured out that reading
strings into VBA IDE containing international characters works, but the
information you provided about using ChrW() function has also been very
helpful.

Regards,

Todd
 
K

Klaus Linke

Yes, I too sometimes use a Unicode text file for "international" strings.

Something like

Dim str As String
Dim iFile As Integer
iFile = FreeFile
Open "C:/unicode.txt" For Binary As #iFile

str = InputB(2, #iFile) ' always FF FE, skip them
str = InputB(LOF(iFile) - 2, #iFile)
Close #iFile
Selection.TypeText str ' display the string

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