Thread.Sleep()
在Access VBA中是否有相同的功能?
Declare Sub Sleep Lib "kernel32" Alias "Sleep" _ (ByVal dwMilliseconds As Long)
使用以下语法调用Sleep函数:
Sub Sleep() Sleep 1000 'Implements a 1 second delay End Sub
不使用kernel32的另一种方法:
Dim started As Single: started = Timer Do: DoEvents: Loop Until Timer - started >= 1
需要进行一些修改才能使代码生效.以下代码是更正后的版本.
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) Sub SleepVBA() Sleep 1000 'Implements a 1 second delay End Sub
使Excel等待的所有其他方法导致Excel变得完全没有响应.使Excel等待同时确保响应式UI的解决方案是使用等待的秒数来调用此等待Sub.
Sub Wait(seconds As Integer) Dim now As Long now = Timer() Do DoEvents Loop While (Timer < now + seconds) End Sub