writes the time to cell A1 and also programs another event five seconds later. : Application OnTime « Application « VBA / Excel / Access / Word






writes the time to cell A1 and also programs another event five seconds later.

 
Dim NextTick As Date
Sub UpdateClock()
    ThisWorkbook.Sheets(1).Range("A1") = Time
    NextTick = Now + TimeValue("00:00:05")
    Application.OnTime NextTick, "UpdateClock"
End Sub
Sub StopClock()
    On Error Resume Next
    Application.OnTime NextTick, "UpdateClock", , False
End Sub

 








Related examples in the same category

1.Run on time
2.Set Refresh Data Timer
3.If you want to keep refreshing the data on a regular basis, you can make the macro run itself
4.Using Application.OnTime to Periodically Analyze Data
5.The OnTime event
6.Scheduling a Macro to Run Every Two Minutes
7.Use OnTime to trigger the refresh data