Option Explicit
msgbox("3秒后获取鼠标坐标")
wscript.sleep 3000
Dim WshShell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application")
set WshShell = CreateObject("wscript.Shell")
Set oBook = oExcel.Workbooks.Add
Set oModule = obook.VBProject.VBComponents.Add(1)
strCode = _
"Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCr & _
"Private Type POINTAPI : X As Long : Y As Long : End Type" & vbCr & _
"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCr & _
"Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub" & vbCr & _
"Public Function GetXCursorPos() As Long" & vbCr & _
"Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCr & _
"End Function" & vbCr & _
"Public Function GetYCursorPos() As Long" & vbCr & _
"Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCr & _
"End Function"
oModule.CodeModule.AddFromString strCode
x = oExcel.Run("GetXCursorPos")
y = oExcel.Run("GetYCursorPos")
WScript.Echo x, y
oExcel.Run "SetCursor", 0, 0
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit