Visually Press CommandButton Through Code

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 3 CommandButtons To Your Form.
'When you press the second button, the first button will be pressed.
'When you press the third button, the first button will be released.
'Insert the following code to the module :

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As _
Long, lParam As Any) As Long
Public Const BM_SETSTATE = &HF3
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202

'Insert the following code to your form:

Private Sub Command2_Click()
Call SendMessage(Command1.hwnd, BM_SETSTATE, 1, ByVal 0&)
End Sub

Private Sub Command3_Click()
Call SendMessage(Command1.hwnd, BM_SETSTATE, 0, ByVal 0&)
End Sub

Go Back