When an Excel application is run through Citrix, the Windows system tray may not be accessible. In such a case, the only option available for a user with multiple languages installed is to change the keyboard layout through VBA.
The physical layout of the keyboard can be changed using the ActivateKeyboardLayout API. |
Instead of passing a language identifier constant, a language string is used as a parameter. For example, by using "English" any of the 13 available English language variants found installed in the user's PC will be selected. The parameter is not case sensitive.
Please read about all available Language Identifier constants and strings in this link.
Please read about all available Language Identifier constants and strings in this link.
Option Explicit 'http://msdn.microsoft.com/en-us/library/windows/desktop/ms646289(v=vs.85).aspx 'http://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx 'http://msdn.microsoft.com/en-gb/goglobal/bb895996 #If Win64 Then Private Declare PtrSafe Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As LongPtr, ByVal Flag As Long) As LongPtr #Else Private Declare Function ActivateKeyboardLayout Lib "user32.dll" (ByVal HKL As Long, Flag As Long) As Long #End If Function ActivateKeyboardLanguage(sLanguage As String) As Boolean Dim oLocale As ListObject Dim vLocale As Variant Dim i As Long Set oLocale = ThisWorkbook.Sheets("LocaleID").ListObjects(1) vLocale = oLocale.DataBodyRange.Cells.Value2 For i = LBound(vLocale) To UBound(vLocale) If InStr(LCase(vLocale(i, 1)), LCase(sLanguage)) > 0 Then If ActivateKeyboardLayout(vLocale(i, 2), 0) <> 0 Then ActivateKeyboardLanguage = True Exit Function End If End If Next i End Function Sub Test() Debug.Print ActivateKeyboardLanguage("English") Debug.Print ActivateKeyboardLanguage("greek") Debug.Print ActivateKeyboardLanguage("elbonian") End Sub Click icon to download an unlocked Excel Workbook with VBA code shown
|