VBA for Excel 2010/2013 - 如何识别系统区域设置 [英] VBA for Excel 2010/2013 - How to identify the system locale

查看:291
本文介绍了VBA for Excel 2010/2013 - 如何识别系统区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个将会有希伯来语和英语的宏,但如果系统语言环境设置为希伯来语,我只想显示希伯来语字符,否则我想用英语进行音译。



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



无论如何,我尝试了几行没有工作,他们是:

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

这些没有用于识别系统区域设置,并输出相同的值,无论是在英语(US)地区或希伯来语(以色列)之一。



任何人都可以告诉我我需要做什么来指示一个数字或文本系统区域设置是什么?

解决方案

我发现这个这里:



您的第一行代码 Application.LanguageSettings.LanguageID(msoLanguageIDUI )给出了对于希伯来语为英语(US)或 1037 的LCID为 1033



您可以使用 Application.LanguageSettings.LanguageID(msoLanguageIDUI)执行简单的 IF 语句)
使用这些数字更改区域设置。


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).

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?

解决方案

I found this here:

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

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

这篇关于VBA for Excel 2010/2013 - 如何识别系统区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆