Move Mouse - VBScript and Excel Macro

对着背影说爱祢 提交于 2019-12-06 11:25:23

First of all, when you do this

Position = "+ 180"
Position = "- 180"

you're first setting Position to be "+180" and then immediately overwriting it to be "-180". There's no point in doing that.

To answer your question more specifically, replace this part:

x & " " & Position & "," & y & " " & Position

with something like this:

x & "," & y

Prior to that you'll have to say what the new coordinates of the cursor should be, e.g.

x = "111"
y = "222"

Also, all of this you don't need and can delete:

GetMessagePos = Excel.ExecuteExcel4Macro( _
    "CALL(""user32"",""GetMessagePos"",""J"")")
x = CLng("&H" & Right(Hex(GetMessagePos), 4))
y = CLng("&H" & Left(Hex(GetMessagePos), (Len(Hex(GetMessagePos)) - 4)))

That's where you get the old cursor position, and you don't need this since you say yourself you don't want to set a relative position.

All in all your script should look something like this:

Option Explicit
Dim Excel, x, y

Set Excel = WScript.CreateObject("Excel.Application")

x = "111"
y = "222"
Excel.ExecuteExcel4Macro ( _
    "CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")

WScript.Sleep (100)
WScript.Echo "Program Ended"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!