I want to send commands to my application even if it is not visible. I have below code, but it is not working as the Excel application is not visible. (I Know code without using sendkeys/postmessage) But here excel application is just taken as example. I have one business object application which I want to operate using sendkeys/postmessage)
Please help me.
I have below code but not solving my problem.
Option Explicit
Declare Function FindWindowX Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As Long, ByVal lpsz2 As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Integer) As Long
Private Const WM_KEYDOWN = &H100
Sub MyProc2()
Dim xl As New Excel.Application
xl.Workbooks.Add
xl.Visible = False
Dim hWind As Variant
Dim cWind As Variant
hWind = xl.hwnd
cWind = FindWindowX(hWind, 0, 0, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKeyH, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKeyI, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, 13, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, 17, 0)
Debug.Print PostMessage(cWind, WM_KEYDOWN, vbKeyH, 0)
Debug.Print cWind
Debug.Print hWind
End Sub