PDA

View Full Version : Get current keyboard layout with VBA



MeiR_ct
04-06-2011, 04:00 AM
(This post is cross-posted from: http://www.mrexcel.com/forum/showthread.php?t=541054)
Hi all.

How can I get the current keyboard layout (language code)?

I'm asking this because when "Application.OnKey" tries to assign a key combination, which contains a character in other layout than the active, it will result run-time error 1004 with the following message:

Method 'OnKey' of object '_Application' failed So I want to check the layout first, before running "Application.OnKey".
And I wonder, can Excel listen and know when the keyboard layout gets changed?

Thanks in advance, Meir.

Paul_Hossler
04-07-2011, 06:08 AM
You might be able to use the .International property, but I'n not sure if it picks up keyboard changes




Application.International Property
Returns information about the current country/region and international settings. Read-only Variant.

xlCountryCodeLongCountry/Region version of Microsoft Excel.
xlCountrySettingLongCurrent country/region setting in the Windows Control Panel.



Paul