4

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?

0m3r
  • 12,286
  • 15
  • 35
  • 71
Ban Atman
  • 177
  • 2
  • 3
  • 10

2 Answers2

2

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.

evoandy
  • 630
  • 4
  • 16
  • 31
0
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:

MSDN

Skip Intro
  • 860
  • 7
  • 12
  • Thanks (@evoandy also) but I have tried this and it returns 1033 for both English (US) and Hebrew (Israel). The PC I am on has the locale set to English (US) and I am remotely connected to my home PC which is set to Hebrew (Israel) so I can test on both. I check the locales via the control panel "Region and Language" section under the Administrative tab. – Ban Atman Mar 19 '13 at 13:55
  • If you go to Excel Options>Language there is the ability to add additional languages. If you change the default office language to hebrew does it return `1037`? – evoandy Mar 19 '13 at 14:20
  • I tried it (required reloading Excel) and it did not change things. I did notice there was a "View display languages installed for each Microsoft program" under Options>Language and there was only English there which might explain the macro editing issue - MS wants more than just the keyboard and locale settings changed in Windows. They want you to buy their language pack for Office though this would be an overkill for me as I don't need dictionaries etc. and just knowing the locale setting would work. – Ban Atman Mar 19 '13 at 15:07