在Excel中使用VBA添加希伯来语自动更正条目

我可以在Excel中使用VBA添加英文自动更正条目

Application.AutoCorrect.AddReplacement What:="helo", Replacement:="hello" 

但是,如果replace字是希伯来语,那么它不起作用(没有添加)

 aHebrewWord = Range("C1").Value Application.AutoCorrect.AddReplacement What:="helo", Replacement:=aHebrewWord 

我知道VBA可以和希伯来语一起工作,即使你不能在VBA中看到希伯来语(源代码在Excel中声明一个在vba中的unicodestring ) – 例如下面的函数可以正常工作:

 function getReverse(aHebrewWord) getReverse=StrReverse(aHebrewWord) end function 

如何使用VBA添加希伯来语自动更正条目?

不应该有任何事情阻止VBA使用一个string而不是另一个; 你的代码应该工作。

这个问题,如果存在的话,可能与你获得一个aHebrewWord的方式aHebrewWord

VBA编辑器希望VBA文件在Windows-1252编码,这是一个8位代码页,不支持希伯来语。

您可以将您的string构build为宽字符代码的串联:

 'this replace 'hello' to 'שלום' Application.AutoCorrect.AddReplacement What:="hello", Replacement:=ChrW(&H05E9) & ChrW(&H05DC) & ChrW(&H05D5) & ChrW(&H05DD) 

或者你可以转换一个Windows-1252string,它是一个相当于unicodestring的二进制文件:

 Application.AutoCorrect.AddReplacement What:="hello", Replacement:=StrConv("éÜÕÝ", vbFromUnicode) 

使用记事本来转换string:复制粘贴unicodestring,将文件保存为unicode(而不是utf-8)并将其打开为ASCII(实际上是Windows-1252),然后将其复制粘贴到VBA编辑器中前两个字符(ÿþ),这是BOM标记。