Tip Printed from ExcelTip.com
Execute Command/Sub-Procedure Using Timer in VBA
This example demostrates how to use a timer to call up a sub procedure after a specific set time has passed.
TimeValue Function is used.
In this example, 3-seconds is assigned to the function.
The Application.OnTime alertTime statement is used to call up the sub procedure, msg, when 3-seconds is up.
Sub timerMsg()
Dim alertTime
MsgBox "The alarm will go off in 3 seconds!"
alertTime = Now + TimeValue("00:00:03")
Application.OnTime alertTime, "msg"
End Sub
Sub msg()
MsgBox "Three Seconds is up!"
End Sub