- Dim Runtime As Date
- Sub RunTimer()
- Runtime = Now() + TimeValue("00:00:01")
- Application.OnTime Runtime, "my_Procedure"
- End Sub
- Sub my_Procedure()
- Range("A1") = Format(Time, "h:mm:ss")
- RunTimer
- End Sub
OnTime函數指在某一具體時間執行某一過程,即過程my_Procedure。
執行my_Procedure的時候,就顯示現在的時間,然後立即執行Runtime過程,接着就循環下去,效果如下圖所示:(顏色大小可以另外設置)