"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 GetXCursorPos() As Long" & vbCrLf & _ "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCrLf & _ "End Function" & vbCrLf & _
"Public Function GetYCursorPos() As Long" & vbCrLf & _ "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCrLf & _ "End Function"
oModule.CodeModule.AddFromString strCode '在模块中添加 VBA 代码 'Author: Demon 'Website: http://demon.tw 'Date: 2011/5/10 x = oExcel.Run("GetXCursorPos") '获取鼠标 X 坐标 y = oExcel.Run("GetYCursorPos") '获取鼠标 Y 坐标
WScript.Echo x, y oExcel.Run "SetCursorPos", 30, 30 '设置鼠标 X Y 坐标 Const MOUSEEVENTF_MOVE = &H1 Const MOUSEEVENTF_LEFTDOWN = &H2