Chinese text display with VBA

S

Susan Kong

Hi,

I tried to extract some Chinese characters and display them in messagebox,
but they are displayed as "????". anybody knows why and how can I make them
properly displayed?

Thanks a lot in advance.


Susan
 
S

Steve Rindsberg

Hi,

I tried to extract some Chinese characters and display them in messagebox,
but they are displayed as "????". anybody knows why and how can I make them
properly displayed?

What font is the system set to use for message boxes? If it's a font that
doesnt include Chinese characters, ??? or empty boxes is probably what you'd
get.
 
S

Susan Kong

It goes like this:

target = rngDoc.Text
MsgBox target

Target is a string and rngDoc is a range object. English strings can be
displayed correctly but not for Chinese characters.

thanks in advance.

Susan
 
T

Tony Jollans

The MsgBox function calls MessageBoxA which takes an ANSI string. For
Chinese characters I think you will need to use an API to call MessageBoxW
which takes a unicode string. Try something like this ..

Private Declare Function APIMsgBox _
Lib "User32" Alias "MessageBoxW" _
(Optional ByVal hWnd As Long, _
Optional ByVal Prompt As Long, _
Optional ByVal Title As String, _
Optional ByVal Buttons As Long) _
As Long

Sub ChineseMessage()

Dim ChinesePrompt As String, Response As String
ChinesePrompt = Selection.Text ' or however you get Chinese text
Response = APIMsgBox(Prompt:=StrPtr(ChinesePrompt), Buttons:=vbYesNo)

End Sub
 
S

Susan Kong

Thanks a lot, Tony, but where should I put the declaration part? Sorry for
my very limited knowledge of VBA.
Compiling error happens when I put it outside my Macro code.

Thanks.

Susan
 
T

Tony Jollans

Hi Susan,

The declaration should go at the top of the module - before the first sub or
function.

If you are already doing that, what error do you get?
 
S

Susan Kong

Hi, Tony,

That works! Thank you very much!

BTW, it did not work because I wrongly placed it between the sub functions.

Susan
Rainbow Network www.365rainbow.com
Ph: (86)10 65802501-25 Fax: (86) 10 65802503 1019 Huapu International Plaza
19 ChaoyangmenWai Avenue Beijing 100020 China
 
Top