Does anyone know how to click a button using code. Probaly using the sendmessage command??
Printable View
Does anyone know how to click a button using code. Probaly using the sendmessage command??
If it's a vb button, simply call the event procedure for that button!
For example, to click the cmdExit button on the current form use cmdExit_Click
It's another button in another application
If you know the Window Handle (hWnd) for that button then you can use SendMessage API to do that:
Usage: ClickButton ButtonHwndCode:Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
Public Sub ClickButton(hwnd As Long)
Call SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0)
Call SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0)
End Sub
Regards,
------------------
Serge
Software Developer
[email protected]
[email protected]
I couldn't get Serge's code to work for a menu, though I'm using the correct menu handle (submenu actually).
Any ideas??
Thanks,
Wade