stop a macro

Z

Zaahir

hi

i have the ffg macro that uses a label and display it as a clock......
the problem is after the application quits the macro continues and the
program re-executes.

the code is below...............

Sub clock()
If ThisWorkbook.Sheets("Client Info").Range("b3").Value = "x" Then Exit Sub
frmMainFrame.lblTime.Caption = Format(Now, "hh:mm:ss AM/PM")
Application.OnTime Now + TimeSerial(0, 0, 1), "clock"
End Sub

the first line of code shud stop the macro bt doesn't

is there a better manner of doing this?
Please Help
thanx in advanced!!!
 
O

Ozgur Pars

I use the below code which I got from someone here in the board...when
terminate the userform I call stoptimer.
Hope it helps,
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, procedure:=cRunWhat, schedule:=True
End Sub

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top