how to move mouse using excel macro

  • Thread starter Thread starter William Yeow
  • Start date Start date
W

William Yeow

hi, i need a macro to move mouse pointer and simulate mouse click to access
activate a report. sendkey dont work as to run the report will require a
mouse buttom click.
 
Hi William

To control the mouse using code try the below. You will need to adjust the
cursor positions to suit your requirement. (in the below example it is
150,200) . Try and feedback.


--Insert a module and copy the below declarations.
'---------------------------------------------------------------------------------
Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" _
(ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function GetMessageExtraInfo Lib "user32" () As Lon
'---------------------------------------------------------------------------------

--Copy the below code to the macro

Private Sub Macro()
'your other code

SetCursorPos 150, 200
mouse_event &H2, 0, 0, 0, GetMessageExtraInfo()
mouse_event &H4, 0, 0, 0, GetMessageExtraInfo()
End Sub


If this post helps click Yes
 
Back
Top