VBScript: Sleep

Posted by SteveHardie | On: Mar 10 2010

VBScript does not implicity allow the Sleep command that you can use in the VB Programming language, to force the script to pause for an amount of time is accomplished by using the Sleep API call. API stands for Application Programming Interface. They are functions found in Windows DLL files. You have to Declare which APIs you will be using. You can declare them only in a Module. For more information about using APIs, click here.

Here is a simple example for using the Sleep API…


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub SleepVBA() 
    Do Until i = 5 
        i = i + 1 
        Range("A1") = i 
        Sleep 1000 
End Sub

comment closed