How to pause for specific amount of time? (Excel/VBA)
instead of using:
Application.Wait(Now + #0:00:01#)
i prefer:
Application.Wait(Now + TimeValue("00:00:01"))
because it is a lot easier to read afterwards.
Add this to your module
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Or, for 64-bit systems use:
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Call it in your macro like so:
Sub Macro1()
'
' Macro1 Macro
'
Do
Calculate
Sleep (1000) ' delay 1 second
Loop
End Sub
Use the Wait method:
Application.Wait Now + #0:00:01#
or (for Excel 2010 and later):
Application.Wait Now + #12:00:01 AM#