如何暂停 vbscript 执行?
问题描述:
如何从内部暂停脚本的执行?类似于 Sleep WinAPI 函数?
How can I pause an execution of a script from within? Something like Sleep WinAPI function?
答
您可以使用 WScript
对象并调用 Sleep
方法就可以了:
You can use a WScript
object and call the Sleep
method on it:
Set WScript = CreateObject("WScript.Shell")
WScript.Sleep 2000 'Sleeps for 2 seconds
另一种选择是直接导入和使用WinAPI函数(仅适用于 VBA,感谢 @Helen):
Another option is to import and use the WinAPI function directly (only works in VBA, thanks @Helen):
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep 2000