MrExcel Publishing
Your One Stop for Excel Tips & Solutions


Posted by John Yuga on August 22, 2001 8:17 PM

Is there any way to have "=SECOND(NOW())" Update
when the system clok changes to next seccond and so on?


John Yuga

Posted by Martin on August 22, 2001 11:01 PM

Here's one way :-

Private Sub Workbook_Open()
Range("A1").NumberFormat = "mm/dd/yy hh:mm:ss"
Call Clock
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
ActiveWorkbook.Saved = True
End Sub

Sub Clock()
Timer = Now + TimeValue("00:00:01")
Application.ontime Timer, "Update"
End Sub

Sub Update()
Range("A1").Value = Now
Call Clock
End Sub

Sub StopTimer()
On Error Resume Next
Application.ontime EarliestTime:=Timer, Procedure:="Update", Schedule:=False
End Sub