Function Delay(Seconds As Long)
Dim StopTime As Date: StopTime = DateAdd("s", Seconds, Now)
Do While Now < StopTime
DoEvents
Loop
End Function
更新如下以获得毫秒精度
Function Delay(Seconds As Double)
Dim StopTime As Double: StopTime = Timer + Seconds
Do While Timer < StopTime
DoEvents
Loop
End Function
对于异步事件,以下可能有效,但目前尚未测试
Function DelayForAsync()
Dim CalculationState As Long
With Application
CalculationState = .Calculation
.Calculation = xlCalculationAutomatic
.CalculateUntilAsyncQueriesDone
Do Until .CalculationState = xlDone
DoEvents
Loop
.Calculation = CalculationState
End With
End Function
1条答案
按热度按时间g6baxovj1#
相反,我使用函数Now和DateAdd实现了延迟:
更新如下以获得毫秒精度
对于异步事件,以下可能有效,但目前尚未测试