このコードは、10 秒ごとに更新される時計を作成します。
ワークブック全体ではなく、特定のセルのみが更新されることに注意してください。これは、計算オプションを好きなように残すことができることを意味します。
Dim SchedRecalc As Date
Sub Recalc()
'Change specific cells
Range("A1").Value = Format(Now, "dd-mmm-yy")
Range("A2").Value = Format(Time, "hh:mm:ss AM/PM")
'or use the following line if you have a cell you wish to update
Range("A3").Calculate
Call StartTime ' need to keep calling the timer, as the ontime only runs once
End Sub
Sub StartTime()
SchedRecalc = Now + TimeValue("00:00:10")
Application.OnTime SchedRecalc, "Recalc"
End Sub
Sub EndTime()
On Error Resume Next
Application.OnTime EarliestTime:=SchedRecalc, _
Procedure:="Recalc", Schedule:=False
End Sub
そして、それが確実に停止するように、This Workbookモジュールで次のようにします。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
EndTime
End Sub