tags:

views:

46

answers:

1

How can I pause an execution of a script from within? Something like Sleep WinAPI function?

A: 

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

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
Oded
Note: You can't run WinAPI functions from VBScript. Your second example works only in VB/VBA.
Helen
@Helen - thanks for the information. Didn't know about this limitation. Answer updated.
Oded