Public Sub Wait(Delay As Variant, Optional ByRef AbortWhenVarTrue As Boolean = False, Optional ByRef AbortWhenVarFalse As Boolean = True)
Dim EndTime As Double
Dim StartTime As Double
Dim D As Single
D = CSng(Delay)
StartTime = Timer
EndTime = StartTime + D
Do While Timer < EndTime
DoEvents
If Timer < StartTime Then
If EndTime > 86398 Then
EndTime = D - (86398 - StartTime)
End If
End If
If AbortWhenVarTrue = True Or AbortWhenVarFalse = False Then
Exit Do
End If
Loop
End Sub