On this forum I found code for getting a digital clock in an Excel sheet. I tried to adapt it for use in a userform. But doesn't update. Here are the two subroutines in the userform module:
' at the top of the module:
Public TimeToRefresh As Date
Sub Userform1_Initialize()
' stuff
End Sub
Public Sub ShowTime()
' Put the time into a field on the form
' calls RefreshTime to make it update regularly
Debug.Print "In ShowTime at " & Time
tboxSystemTime.text = Format(Time, "h:mm:ss ")
RefreshTime
Debug.Print "In ShowTime at " & Time & " Called Refresh"
End Sub
Sub RefreshTime()
' makes ShowTime run at regular intervals
Debug.Print "Entered RefreshTime at " & Time
TimeToRefresh = Now + TimeValue("00:00:01")
Debug.Print "In RefreshTime, TimeToRefresh = " & TimeToRefresh
Application.OnTime TimeToRefresh, "ShowTime"
End Sub
The Debug.print statements give:
In ShowTime at 08:24:24
Entered RefreshTime at 08:24:24
In RefreshTime, TimeToRefresh = 22/6/2009 08:24:25
In ShowTime at 08:24:24 Called Refresh
So the RefreshTime subroutine is calling ShowTime immediately instead of waiting for one second, and when ShowTime is called for the second time, it does not then call RefreshTime. I've done my best to get my head around this, without success.
Bookmarks