how to move mouse using excel macro

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.
 
J

Jacob Skaria

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top