Is there an equivalent to Thread.Sleep() in VBA Is there an equivalent to Thread.Sleep() in VBA vba vba

Is there an equivalent to Thread.Sleep() in VBA


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

Use the following syntax to call the Sleep function:

Sub Sleep()Sleep 1000 'Implements a 1 second delayEnd Sub 


Another way without using kernel32:

Dim started As Single: started = TimerDo: DoEvents: Loop Until Timer - started >= 1


A couple of amendments are required to get the code to work.The code below is the corrected version.

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)Sub SleepVBA() Sleep 1000 'Implements a 1 second delay End Sub