目前这个脚本运行5分钟,但我需要通过击键来阻止它。使用vbs按键击杀while循环
Option Explicit
Dim Excel, x, y, x1, y1, eTime
Set Excel = WScript.CreateObject("Excel.Application")
eTime = DateAdd("n", 2, Now)
x = "111"
y = "222"
x1 = "222"
y1 = "111"
Do While Now < eTime
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x1 & "," & y1 & ")")
WScript.Sleep (1000)
Loop
WScript.Echo "Program Ended"
我试过下面的代码,但它不工作,我做错了吗?
Option Explicit
Dim Excel, x, y, x1, y1, eTime
Set Excel = WScript.CreateObject("Excel.Application")
eTime = DateAdd("n", 2, Now)
x = "111"
y = "222"
x1 = "222"
y1 = "111"
Sub Form_KeyPress(KeyAscii As Integer)
Do While Not KeyAscii = 27
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
Excel.ExecuteExcel4Macro (_
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x1 & "," & y1 & ")")
WScript.Sleep (1000)
Loop
WScript.Echo "Program Ended"
纯VBScript不能做你想做的,但VBA可以([相关](https://stackoverflow.com/q/23725598/1630171))。 –