Timing Delays in VBA
Solution 1:
If you are in Excel VBA you can use the following.
Application.Wait(Now + TimeValue("0:00:01"))
(The time string should look like H:MM:SS.)
Solution 2:
I use this little function for VBA.
Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Error_GoTo
Dim PauseTime As Variant
Dim Start As Variant
Dim Elapsed As Variant
PauseTime = NumberOfSeconds
Start = Timer
Elapsed = 0
Do While Timer < Start + PauseTime
Elapsed = Elapsed + 1
If Timer = 0 Then
' Crossing midnight
PauseTime = PauseTime - Elapsed
Start = 0
Elapsed = 0
End If
DoEvents
Loop
Exit_GoTo:
On Error GoTo 0
Exit Function
Error_GoTo:
Debug.Print Err.Number, Err.Description, Erl
GoTo Exit_GoTo
End Function
Solution 3:
You can copy this in a module:
Sub WaitFor(NumOfSeconds As Long)
Dim SngSec as Long
SngSec=Timer + NumOfSeconds
Do while timer < sngsec
DoEvents
Loop
End sub
and whenever you want to apply the pause write:
Call WaitFor(1)
I hope that helps!