How to cancel the OnTime Method? Thanks NateO!

L

Legacy 98055

Guest
Hi Guys.

In the following procedure, when the user places a check in in this CheckBox, a procedure is run every 60 seconds.

The code continues looping until the checkbox is unchecked.

What is the code needed to cancel the OnTime method?

The help files for the OnTime method only give an example for a static time, not a loop.

This is the line I am using in my attempt to cancel the method.<pre>

Application.OnTime Procedure:="RefreshDeTime", Schedule:=False</pre>

Thanks,
Tom<pre>


Private Sub CheckBox1_Click()

Do Until CheckBox1.Value = False
Application.OnTime Now + TimeValue("00:00:60"), "RefreshDeTime"
Sheet1.Range("D2").Value = Now
ActiveWorkbook.save
Loop
Application.OnTime Procedure:="RefreshDeTime", Schedule:=False

End Sub</pre>
This message was edited by TsTom on 2002-04-26 15:12
This message was edited by TsTom on 2002-04-26 15:41
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Ts, you may want read Chip's perspective on the desirability of storing the time in a variable (bottom half).

http://www.cpearson.com/excel/ontime.htm

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-26 15:45
 
Upvote 0
Thanks NateO
Works just as I needed..
Tom<pre>


#########################################
Standard Module TimerRefresh
#########################################

Public RunWhen As Date

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, 5)
Application.OnTime earliesttime:=RunWhen, procedure:="RefreshDeTime", _
schedule:=True
End Sub

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

Sub RefreshDeTime()
Sheet1.Range("D2").Calculate
ActiveWorkbook.save
StartTimer
End Sub
#########################################








#########################################
Class Module Workbook
#########################################
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub
#########################################








#########################################
Class Module Sheet1(PSRT Tracking)
#########################################
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
RefreshDeTime
Else
StopTimer
End If
End Sub
#########################################</pre>
This message was edited by TsTom on 2002-04-26 15:42
 
Upvote 0
Glad to hear you're up and running. Have a great weekend! Say, neat trick changing the post title, is this an option for an original poster? I'm off to the test section....

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-27 15:18
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top