View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Richard Edwards[_2_] Richard Edwards[_2_] is offline
external usenet poster
 
Posts: 24
Default Excel function to update time every minute

thanks for that but it will not be available as a custom function...?


"Peter T" <peter_t@discussions wrote in message
...
Private nextTime As Date

Sub UpdateTime()
nextTime = Now + TimeValue("00:00:02") ' << change to 00:01:00
Application.OnTime nextTime, "TimeUp"
End Sub

Sub TimeUp()
Static n As Long ' just for testing
n = n + 1
Cells(n, 1) = Time
UpdateTime
End Sub

Sub StopUpdate()
If nextTime Then
Application.OnTime nextTime, "TimeUp", , False
nextTime = 0
End If
End Sub

Sub auto_close()
' be sure to stop in a close event
StopUpdate

End Sub


Regards,
Peter T

"Richard Edwards" wrote in message
...
Afternoon all,

Is it possible to create custom function that updates the time every
minute?

I have the following code that will update the time:

Sub UpdateTime()
Application.OnTime Now + TimeValue("00:01:00"), "TimeUp"

End Sub
Sub TimeUp()
[a1] = Time
End Sub

But i have no idea how to wrap this (if it is even possible!) into a
custom function...

Thank you.

Richard