Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your declaration for the ActivateKeyboardLayout is actually incorrect. For 32-bit systems your code should be something like this:</p> <pre><code>Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As Long, _ ByVal flags As Long) As Long Const aklPUNJABI As Long = &amp;H4460446 Dim oldLayout as Long oldLayout = ActivateKeyboardLayout(aklPUNJABI, 0) If oldLayout = 0 Then 'Oops an error' Else 'Save old layout for later restore?' End If </code></pre> <p>The 64-bitness of the operating system is a bit of a red herring in this case. Since you are running a VBA app it must be running as a 32-bit app regardless of OS. I suspect your problem may be that on your Vista system the Punjabi keyboard layout that you want is not loaded. ActivateKeyboardLayout will only work to activate a keyboard layout that is already loaded. For some reason the designers of this API felt that failure due to the keyboard layout not existing was not an error so the LastDllError is not set. You may want to look into using LoadKeyboardLayout for this type of situation.</p> <p>EDIT: To double check that the keyboard layout you are trying to get is actually loaded you can use this:</p> <pre><code>Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal size As Long, _ ByRef layouts As Long) As Long Dim numLayouts As Long Dim i As Long Dim layouts() As Long numLayouts = GetKeyboardLayoutList(0, ByVal 0&amp;) ReDim layouts(numLayouts - 1) GetKeyboardLayoutList numLayouts, layouts(0) Dim msg As String msg = "Loaded keyboard layouts: " &amp; vbCrLf &amp; vbCrLf For i = 0 To numLayouts - 1 msg = msg &amp; Hex(layouts(i)) &amp; vbCrLf Next MsgBox msg </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload