MS Word VBA to display Unicode strings

2019-01-15 22:21发布

We have some VBA code in MS Word 2010 which needs to display Persian (Farsi) words dynamically; in other words, depending on which buttons the user clicks on the VBA app window, we will display a different string of Persian.

The only way we discovered to do this was to use something like this and concatenate a very long string character by character: the ChrW(&633). Do you know another way we can do this? The strings will remain the same, but we need a couple of different ones. Can they be loaded from a file?

Your help is much appreciated. Thanks.

1条回答
手持菜刀,她持情操
2楼-- · 2019-01-15 23:21

Lets have an UTF-8 text file unicode.txt, a form UserForm1 with label Label1 and Button CommandButton1:

'ensure reference is set to Microsoft ActiveX DataObjects library 
'(the latest version of it) under "tools/references"

Dim adoStream As ADODB.Stream
Dim var_String As Variant

Set adoStream = New ADODB.Stream

adoStream.Charset = "UTF-8"
adoStream.Open
adoStream.LoadFromFile "unicode.txt"

Label1 = adoStream.ReadText

adoStream.Close
查看更多
登录 后发表回答