#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Timer Event

What is the best way to get some code to run at timed intervals?

I have used the following code.

Application.OnTime Now + TimeValue("00:05:00"), _ "time_set",
TimeValue("22:00:00")

This should run every 5 minutes until 22:00 Hours.

I have also tried:-

Application.OnTime Now + TimeValue("00:05:00"), "time_set", ,False

I get debugging errors with both.

Would a Do_Loop be better?

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Timer Event

To cancel an OnTime timer, you must pass it the EXACT time that was set in
the code that called OnTime. You should create a module level Double
variable, store the time in that variable, and then pass that value when you
cancel the timer.

See www.cpearson.com/excel/ontime.htm for details.


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


"Saxman" wrote in message
...
What is the best way to get some code to run at timed intervals?

I have used the following code.

Application.OnTime Now + TimeValue("00:05:00"), _ "time_set",
TimeValue("22:00:00")

This should run every 5 minutes until 22:00 Hours.

I have also tried:-

Application.OnTime Now + TimeValue("00:05:00"), "time_set", ,False

I get debugging errors with both.

Would a Do_Loop be better?

TIA



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Timer Event

Chip Pearson wrote:
To cancel an OnTime timer, you must pass it the EXACT time that was set in
the code that called OnTime. You should create a module level Double
variable, store the time in that variable, and then pass that value when you
cancel the timer.


I get constant errors when running this. Do I have to alter the values
in the Sub StartTimer() routine?
.................................................. ..........
Public RunWhen As Double
Public Const cRunIntervalSeconds = 30 ' 30 seconds
Public Const cRunWhat = "The_Sub"

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

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

Sub The_Sub()
Private Sub Worksheet_Calculate()
Application.EnableEvents = False

Worksheets("Data").Range("F5:F10").Copy
Worksheets("Archive").Range("A2").Insert Shift:=xlDown

Application.EnableEvents = True
StartTimer
End Sub
.................................................. ...................

Sorry, but I'm very green at this.

Thanks.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer event dhstein Excel Discussion (Misc queries) 2 June 18th 09 04:16 PM
Timer Event Saxman[_5_] Excel Programming 8 December 12th 05 11:18 PM
Macro With Timer Event Saxman Excel Discussion (Misc queries) 4 December 12th 05 05:35 PM
Timer Event Saxman Excel Discussion (Misc queries) 3 November 22nd 05 09:27 AM
Timer Event Chris Miller[_2_] Excel Programming 1 August 4th 03 06:18 PM


All times are GMT +1. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"