除了Application.Wait或Application.Sleep以外,延迟宏的更好方法是? [英] Better way to delay macro other than Application.Wait or Application.Sleep?
问题描述
我创建了一个状态栏,该栏在application.wait之外有效.从某种意义上说,这很好.但是,我希望能够在处理其他工作表时更新状态栏.我找不到合适的方法.以下是到目前为止的内容.
I created a status bar that works off of application.wait. In a sense, that worked quite well. However, I want to be able to update the status bar while working on other worksheets. I am unable to find a suitable method. Below is what I have thus far.
Private i As Integer
Private newHour
Private newMinute
Private newSecond
Private waitTime
Private Sub UserForm_Activate()
For i = 1 To 10
UserForm1.Label1.Width = UserForm1.Label1.Width + 24
Application.Calculate
If Application.CalculationState = xlDone Then
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
End If
Next
UserForm1.Hide
End Sub
注意:出于某种奇怪的原因,我可以使标签不断更新的唯一方法是使用Application.Calculate.否则,它将等待整整10秒钟,然后状态栏将达到最大扩展名,然后隐藏用户窗体.
NOTE: For some odd reason the only way I could get the label to constantly update was to use Application.Calculate. Otherwise, it would wait the full 10 seconds, and then the status bar would reach maximum extension before hiding the userform.
推荐答案
使用此延迟函数代替Application.Wait
Private Sub delay(seconds As Long)
Dim endTime As Date
endTime = DateAdd("s", seconds, Now())
Do While Now() < endTime
DoEvents
Loop
End Sub
这篇关于除了Application.Wait或Application.Sleep以外,延迟宏的更好方法是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!