How to enable Unicode in Excel 2016 VBA editor

家住魔仙堡 提交于 2021-02-07 19:51:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!