VBA to open Onscreen keyboard in 64bit Excel

  32bit-64bit, 64-bit, excel, vba, windows

I am trying to open the osk.exe from VBA within Excel 64 bit on Windows 10 64 bit.

I have pieced together the following code that works for 32bit Excel on 64bit Windows 10, but I don’t know how to modify it to get it working again with 64bit Excel:

Option Explicit

    cbSize As LongPtr
    fMask As Long
    hwnd As LongPtr
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As LongPtr
    hProcess As Long
End Type

Public Declare PtrSafe Function ShellExecuteEx Lib "shell32.dll" _
                                       (lpExecInfo As SHELLEXECUTEINFO) As LongPtr

Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As LongPtr) As Boolean
Declare PtrSafe Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As LongPtr) As Boolean

Public Function KeyboardOpen()
  Dim lngPtr As LongPtr

   With shInfo
      .cbSize = Len(shInfo)
      .lpFile = "C:WindowsSysnativecmd.exe" 'best to use Known folders here
      .lpParameters = "/c start osk.exe"
      .lpDirectory = "C:windowssystem32" 'best to use Known folders here
      .lpVerb = "open"
      .nShow = 0
   End With
   Call Wow64DisableWow64FsRedirection(lngPtr)
   Call ShellExecuteEx(shInfo)
   Call Wow64RevertWow64FsRedirection(lngPtr)
End Function

Sub OpenKeyboard()
Call KeyboardOpen
End Sub

Source: Windows Questions