MS Word VBA 显示 Unicode 字符串 [英] MS Word VBA to display Unicode strings
问题描述
我们在 MS Word 2010 中有一些 VBA 代码需要动态显示波斯语(波斯语)单词;换句话说,根据用户在 VBA 应用程序窗口上单击的按钮,我们将显示不同的波斯语字符串.
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.
我们发现这样做的唯一方法是使用类似的方法并逐个字符连接一个很长的字符串:ChrW(&633)
.你知道我们可以这样做的另一种方法吗?字符串将保持不变,但我们需要几个不同的字符串.它们可以从文件中加载吗?
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.
推荐答案
让我们有一个 UTF-8 文本文件 unicode.txt,一个带有标签 的表单 UserForm1>Label1 和按钮 CommandButton1:
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
这篇关于MS Word VBA 显示 Unicode 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!