Detect Keyboard language

Status
Not open for further replies.

cycle_simon

Board Regular
Joined
Jun 13, 2007
Messages
56
Can some point to where I can detect the language setting of a user's keyboard and if there is a list of codes for the various languages so that I could do something like:

Code:
if KeyboardLanguage = XXXX then
    .....

elseif KeyboardLanguage = YYYY then
  ......

end if
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You can use the API GetKeyboardLayoutName to easily achieve this.

Below is a handy VBA wrapper function named (KeyboardLanguage) :

Code:
Option Explicit
 
Private Type LangCode
    English As Boolean
    French As Boolean
    Spanish As Boolean
    Arabic As Boolean
    [COLOR=seagreen][B]'add other languages here...[/B][/COLOR]
End Type
 
Private Const KL_NAMELENGTH As Long = 9
    
Private Declare Function GetKeyboardLayoutName Lib "user32" _
    Alias "GetKeyboardLayoutNameA" ( _
    ByVal pwszKLID As String) As Long
    
Sub Test()
 
    Const MSG As String = _
    "The KeyBoard Language for the current Process is : "
 
    If KeyboardLanguage.English Then
 
        MsgBox MSG & "'English'"
 
    ElseIf KeyboardLanguage.French Then
 
        MsgBox MSG & "'French'"
 
    ElseIf KeyboardLanguage.Spanish Then
 
        MsgBox MSG & "'Spanish'"
        
    ElseIf KeyboardLanguage.Arabic Then
 
        MsgBox MSG & "'Arabic'"
 
    [COLOR=seagreen][B]'ElseIf .......[/B][/COLOR]

    Else
    
        MsgBox "Unknown Keyboard Language."
        
    End If
 
End Sub

Private Function KeyboardLanguage() As LangCode
 
    Dim tLC As LangCode
    Dim sBuffer As String
    
    sBuffer = Space(KL_NAMELENGTH - 1)
    GetKeyboardLayoutName sBuffer
    
    Select Case Right(sBuffer, 2)
    
        Case "09"
            tLC.English = True
        Case "0C"
            tLC.French = True
        Case "0A"
            tLC.Spanish = True
        Case "01"
            tLC.Arabic = True
        
    End Select
    
    KeyboardLanguage = tLC
    
End Function

To find out about Language Identifier Constantes see HERE .
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top