'*************************************** ********************************
'Code starts
'*************************************** ********************************
Set mouse = new setmouse
Mouse. getpos X, y'' to get the coordinates of the current mouse position
Msgbox X & "" & Y
Mouse. Move 60, 14 'move the mouse to the coordinates
Wscript. Sleep 200
Mouse. clik "dbclick" 'left-click
'"Right" right click, "Middle" Intermediate key click
* After you add the following code to the vbs file, you can call the preceding method ********* **************************************** **************************************** **
'*************************************** **************************************** **************************************** *****************************
Class setmouse
Private s
Private xls, wbk, module1
Private reg_key, xls_code, X, Y
Private sub class_initialize ()
Set XLS = Createobject ("Excel. application ")
Set S = Createobject ("wscript. Shell ")
'Vbs full control Excel
Reg_key = "HKEY_CURRENT_USER \ Software \ Microsoft \ Office \ $ \ Excel \ SECURITY \ accessvbom"
Reg_key = Replace (reg_key, "$", XLS. Version)
S. regwrite reg_key, 1, "REG_DWORD"
'Model code
Xls_code = _
"Private type pointapi: X as long: Y as long: end type" & vbcrlf &_
"Private declare function setcursorpos lib" "USER32" "(byval X as long, byval y as long) As long" & vbcrlf &_
"Private declare function getcursorpos lib" "USER32" (lppoint as pointapi) As long "& vbcrlf &_
"Private declare sub mouse_event lib" "USER32" "alias" "mouse_event """_
& "(Byval dwflags as long, byval DX as long, byval dy as long, byval cbuttons as long, byval dwextrainfo as long)" & vbcrlf &_
"Public Function getx () as long" & vbcrlf &_
"Dim Pt as pointapi: getcursorpos PT: getx = pt. X" & vbcrlf &_
"End function" & vbcrlf &_
"Public Function Gety () as long" & vbcrlf &_
"Dim Pt as pointapi: getcursorpos PT: Gety = pt. Y" & vbcrlf &_
"End function"
Set wbk = XLS. workbooks. Add
Set module1 = wbk. vbproject. vbcomponents. Add (1)
Module1.codemodule. addfromstring xls_code
End sub
'Close
Private sub class_terminate
XLS. displayalerts = false
Wbk. Close
XLS. Quit
End sub
'Calling' Process
Public sub getpos (x, y)
X = XLS. Run ("getx ")
Y = XLS. Run ("Gety ")
End sub
Public sub move (x, y)
XLS. Run "setcursorpos", X, Y
End sub
Public sub clik (keydown)
Select case ucase (keydown)
Case "left"
XLS. Run "mouse_event", & H2 + & H4, 0, 0, 0, 0
Case "right"
XLS. Run "mouse_event", & H8 + & H10, 0, 0, 0, 0
Case "Middle"
XLS. Run "mouse_event", & H20 + & h40, 0, 0, 0
Case "dbclick"
XLS. Run "mouse_event", & H2 + & H4, 0, 0, 0, 0
XLS. Run "mouse_event", & H2 + & H4, 0, 0, 0, 0
End select
End sub
End Class
'*************************************** ********************************
'Code ended
'*************************************** ********************************
'*************************************** **************************************** **************************************** *****************************