Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3
#If VBA7 Then
Public Declare PtrSafe Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
#Else
Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
#End If
Sub openTouchKeyboard()
Dim RetVal As Long
On Error Resume Next
RetVal = ShellExecute(0, "open", "C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe", _
0, "C:\Program Files\Common Files\microsoft shared\ink\", SW_SHOWMAXIMIZED)
End Sub
Public Function closeIfOpen() As Boolean
Dim objWINMGMTS As Object
Dim objApps As Object
Dim objApp As Object
Set objWINMGMTS = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objApps = objWINMGMTS.ExecQuery("select * from win32_process where name='tabtip.exe'") 'or osk.exe depending on kb in use
For Each objApp In objApps
objApp.Terminate
Next
End Function