Thread: time
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ozgur Pars[_2_] Ozgur Pars[_2_] is offline
external usenet poster
 
Posts: 70
Default time

Zaahir,
in a module you can copy the code below:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub

Sub The_Sub()
ActiveSheet.Shapes(1).Select
Selection.Characters.Text = Format(Now, "hh:mm:ss")
Call StartTimer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=False
End Sub


And in the "this.workbook" :

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub


The label shows the time continuasly once you execute the The_Sub procedure...

Hope this helps,
Ozgur


"Zaahir" wrote:

Thanx Ozgur, but where do i put all these codes?

"Ozgur Pars" wrote:

Hi Zaahir,
I tried to do the same on my userform and was told that in order for the
label to get constantatly updated one has to call a procedure every second
here is the code I got from the internet...(it updates every 60 seconds so
if you want it to update every second change to 1 and change the format to
hh:mm:ss)

Regards,
Ozgur

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Zaahir" wrote:

hi

i want to make a clock using a label, but of i use the time & now values,
the result returned is the time at which the macro was run....
How do i get the a watch response out of the label, to give me hh:mm:ss
continuously?
Regards