VBA for Excel 2010/2013 - 如何识别系统区域设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15500552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:06:46  来源:igfitidea点击:

VBA for Excel 2010/2013 - How to identify the system locale

excelvbaexcel-vba

提问by Ban Atman

I am writing a macro that will have both Hebrew and English language in it, but I would only like to display Hebrew characters if the system locale is set to Hebrew and otherwise I want to transliterate in English.

我正在编写一个包含希伯来语和英语的宏,但如果系统区域设置为希伯来语,我只想显示希伯来语字符,否则我想用英语音译。

This is due to a quirk in the way Excel macros seems to deal with languages or at least Hebrew (for some reason even if you have the keyboard set to Hebrew and will output Hebrew in almost every application, it will not for the Excel macro editor until you set the system local to be Hebrew as well and so the spreadsheet will also not show Hebrew even though if you typed it directly in the cell it would show fine - this is true for Excel 2010 and 2013 at least).

这是由于 Excel 宏似乎处理语言或至少是希伯来语的方式的一个怪癖(出于某种原因,即使您将键盘设置为希伯来语并且几乎在每个应用程序中都会输出希伯来语,它不会用于 Excel 宏编辑器直到您将系统本地设置为希伯来语,因此电子表格也不会显示希伯来语,即使您直接在单元格中输入它也会显示正常 - 至少对于 Excel 2010 和 2013 是这样)。

In any case, I have tried several lines which have not worked and they are:

无论如何,我尝试了几行没有用的行,它们是:

Application.LanguageSettings.LanguageID(msoLanguageIDUI)
Application.LanguageSettings.LanguageID(msoLanguageIDInstall)
Application.LanguageSettings.LanguagePreferredForEditing(msoLanguageIDHebrew)

These have not worked in identifying the system locale and output the same value whether on an English (US) locale or Hebrew (Israel) one.

无论是在英语(美国)语言环境还是希伯来语(以色列)语言环境中,这些都无法识别系统语言环境并输出相同的值。

Can anyone tell me what I need to do to indicate either by a number or text what the system locale is?

谁能告诉我我需要做什么才能通过数字或文本指示系统区域设置是什么?

回答by evoandy

I found this here:

我在这里找到了这个

Your first line of code Application.LanguageSettings.LanguageID(msoLanguageIDUI)gives the LCID which would be 1033for English (US) or 1037for Hebrew.

您的第一行代码Application.LanguageSettings.LanguageID(msoLanguageIDUI)给出了1033用于英语(美国)或1037希伯来语的 LCID 。

You could do a simple IFstatement using Application.LanguageSettings.LanguageID(msoLanguageIDUI)to change the locale using these figures.

您可以 使用这些数字来更改语言环境,从而做一个简单的IF陈述Application.LanguageSettings.LanguageID(msoLanguageIDUI)

回答by Skip Intro

Sub LangCheck()

   Dim lang_code As Long
        lang_code = Application.LanguageSettings.LanguageID(msoLanguageIDUI)

        MsgBox lang_code

End Sub

US is 1033, Hebrew is 1037, according to this link:

根据此链接,美国是 1033,希伯来语是 1037:

MSDN

MSDN