PC Review


Reply
Thread Tools Rate Thread

Cancel Ontime routine

 
 
Riddler
Guest
Posts: n/a
 
      1st Oct 2007
I have a ontime routine that gets called when the workbook is opened.
It has the spreadsheet recalculate every 5 seconds. That works fine.
The problem I have is trying to cancel it. I use the exact same syntax
when I started it with the exception of Schedule:= False to cancel it.
I get a "Method 'OnTime' of Object'_Application' failed" error. Can
anyone help figure out what I am missing or is wrong?

Thanks
Scott

Sub AutoUpDater()
Calculate 'Recalculates the spreadsheet
Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
procedure:="AutoUpDater", Schedule:=True
End Sub

Sub CancelAutoUpdater()
Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
procedure:="AutoUpDater", Schedule:=False
End Sub

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      1st Oct 2007
To clear an OnTime routine, you must provide the EXACT time for which the
event was scheduled. Clearly (or it should be clear) that you can't simply
use "Now+TimeValue("00:00:05")" as the time of the event because Now will
return a different value (the current time of day) every time it is called.
Store your time to run in a Public variable (declared above and outside of
any procedure) and use that value.

Public RunWhen As Double
Sub AutoUpdater()
RunWhen = Now+TimeSerial(0,0,5)
Application.OnTime RunWhen,"AutoUpdater",,True
End Sub

Sub CancelOnTime()
Application.OnTime RunWhen,"AutoUpdater",,False
End Sub

See www.cpearson.com/Excel/OnTime.aspx for additional details.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Riddler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a ontime routine that gets called when the workbook is opened.
> It has the spreadsheet recalculate every 5 seconds. That works fine.
> The problem I have is trying to cancel it. I use the exact same syntax
> when I started it with the exception of Schedule:= False to cancel it.
> I get a "Method 'OnTime' of Object'_Application' failed" error. Can
> anyone help figure out what I am missing or is wrong?
>
> Thanks
> Scott
>
> Sub AutoUpDater()
> Calculate 'Recalculates the spreadsheet
> Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
> procedure:="AutoUpDater", Schedule:=True
> End Sub
>
> Sub CancelAutoUpdater()
> Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
> procedure:="AutoUpDater", Schedule:=False
> End Sub
>


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      1st Oct 2007
Take a look at Chip Pearson's notes:
http://www.cpearson.com/excel/OnTime.aspx

Pay particular attention to how he stores the next time (in the RunWhen
variable) so he can cancel any pending ontime procedure.

Riddler wrote:
>
> I have a ontime routine that gets called when the workbook is opened.
> It has the spreadsheet recalculate every 5 seconds. That works fine.
> The problem I have is trying to cancel it. I use the exact same syntax
> when I started it with the exception of Schedule:= False to cancel it.
> I get a "Method 'OnTime' of Object'_Application' failed" error. Can
> anyone help figure out what I am missing or is wrong?
>
> Thanks
> Scott
>
> Sub AutoUpDater()
> Calculate 'Recalculates the spreadsheet
> Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
> procedure:="AutoUpDater", Schedule:=True
> End Sub
>
> Sub CancelAutoUpdater()
> Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), _
> procedure:="AutoUpDater", Schedule:=False
> End Sub


--

Dave Peterson
 
Reply With Quote
 
Riddler
Guest
Posts: n/a
 
      2nd Oct 2007
Works great! I was wondering how "exact" exact meant. I thought the 5
second interval was all that it needed but obviously it didnt work.
Thank a bunch.

Scott Riddle
Mech. Eng.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find %ontime & SUMIF ontime ie: find matching sets within Range... Chris T-M Microsoft Excel Worksheet Functions 3 10th Oct 2008 08:14 PM
Cancel Button Routine =?Utf-8?B?VG9mZXJLaW5n?= Microsoft Excel Programming 2 14th May 2006 04:17 PM
VBA routine in detail on print routine causing errors in report Jeff Wimer Microsoft Access Reports 0 21st Oct 2005 01:54 AM
Cancel OnTime MAS Microsoft Excel Programming 1 1st May 2005 02:37 PM
how do I make a routine run after the 'cancel' butten is pressed . =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Programming 13 10th Jan 2005 05:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 AM.