简体   繁体   English

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

[英]Adding a Hebrew Autocorrect entry using VBA in Excel

I can add an English Autocorrect entry using VBA in Excel 我可以在Excel中使用VBA添加英文自动更正条目

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

However if the replacement word is Hebrew then it doesn't work (nothing is added) 但是,如果替换词是希伯来语,那么它将不起作用(未添加任何内容)

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

I know that VBA does work with Hebrew, even though you can't actually see Hebrew in VBA (source declaring a unicode string in vba in excel ) - for instance the following function works fine: 我知道VBA确实可以与希伯来语一起使用,即使您实际上在VBA中看不到希伯来语(源代码在excel中的vba中声明了unicode字符串 )-例如,以下功能可以正常工作:

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

How can I add a Hebrew Autocorrect entry using VBA? 如何使用VBA添加希伯来语自动更正条目?

There shouldn't be anything preventing VBA from using one string instead of another; 不应阻止VBA使用一个字符串而不是另一个字符串。 your code should work. 您的代码应该可以工作。

The problem, if it exists, might be with the way you're obtaining aHebrewWord . 如果存在问题,则可能与您获取aHebrewWord的方式aHebrewWord

The VBA editor expects VBA files to be encoded in Windows-1252 , which is a 8-bit codepage and does not support hebrew. VBA编辑器希望VBA文件在Windows-1252进行编码,这是8位代码页,不支持希伯来语。

You can either build your string as a concatenation of wide character code : 您可以将字符串构建为宽字符代码的串联:

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

Or you can convert a Windows-1252 string which is a binary equivalent of the unicode string: 或者,您可以转换Windows-1252字符串,该字符串等效于unicode字符串:

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

Use notepad to convert the string: copy-paste the unicode string, save the file as unicode (not utf-8) and open it as ASCII (which is in fact Windows-1252),then copy-paste it into the VBA editor without the first two characters (ÿþ), which is the BOM marker. 使用记事本转换字符串:复制并粘贴unicode字符串,将文件另存为unicode(不是utf-8)并以ASCII打开(实际上是Windows-1252),然后将其复制粘贴到VBA编辑器中,而无需前两个字符(ÿþ),即BOM表标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM