问题
I have a worksheet with Hebrew word "שלום" in cell A1.
I am trying to run this VBA code:
Sub test()
Dim str As String
str = Range("A1")
MsgBox str
End Sub
The message box displays:
????
Also, when I try to write Hebrew characters in VBA code:
if range("A1") = "שלום" then 'do something...'
instead of Hebrew letters I see gibberish.
I use Excel 2016 on Windows 10. Hebrew language pack is installed.
I did not face this problem in Excel 2010 on Windows 7.
Anyone with an idea for enabling Hebrew (or Unicode in general) in VBA code?
回答1:
You need to set system locale to Hebrew.
Different version of Windows has a slightly different way of doing it. Search the net for how to do it on your version of Windows. Basically, it is in Control Panel/Language & Region. If you are using Windows 10, it is under Settings/Time & Language/Region/Additional Date, Time, & Regional Setting (on the upper right hand corner of the window)/Region (change date, time, or number formats)/Administrative.
来源:https://stackoverflow.com/questions/34745025/how-to-enable-unicode-in-excel-2016-vba-editor