ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to move mouse using excel macro (https://www.excelbanter.com/excel-programming/434059-how-move-mouse-using-excel-macro.html)

William Yeow

how to move mouse using excel macro
 
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.

Jacob Skaria

how to move mouse using excel macro
 
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 Long
'---------------------------------------------------------------------------------

--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
---------------
Jacob Skaria


"William Yeow" wrote:

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.


Jacob Skaria

how to move mouse using excel macro
 
In the mean while I assume you already know about AppActivate Function which
activates an application that is already running.

http://msdn.microsoft.com/en-us/libr...hy(VS.80).aspx

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

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 Long
'---------------------------------------------------------------------------------

--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
---------------
Jacob Skaria


"William Yeow" wrote:

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.



All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com