excel vba中如何实现时间等待?

2026年09月09日 01:43
有2个网友回答
网友(1):

VB中有一个API函数叫Sleep可以实现暂停。或者用下面的自定义过程waitsec来实现暂停。
Sub mmm()
MsgBox "XX"
waitsec 2
MsgBox "XX"
waitsec 2
MsgBox "XX"
End Sub
Private Sub waitsec(ByVal dS As Double)
Dim sTimer As Date
sTimer = Timer
Do
DoEvents
Loop While Format((Timer - sTimer), "0.00") < dS
End Sub

网友(2):

Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:05"), "AAA"
Application.OnTime Now + TimeValue("00:00:05"), "BBB"
Application.OnTime Now + TimeValue("00:00:05"), "CCC"
End Sub