#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Timer event

I'm setting up a timer event based on Chip Pearson's code which is shown below.
This works fine when I run the StartTimer code. I'd like to have this code
run when the workbook starts - so I tried putting the code in the
"ThisWorkbook" module - but then the timer event doesn't work. Any help is
appreciated.


Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "TheSub" ' the name of the procedure to run


Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat, _
Schedule:=True
End Sub

'This stores the time to run the procedure in the variable RunWhen, two
minutes after the current time.

'Next, you need to write the procedure that will be called by OnTime. For
example,

Sub TheSub()
''''''''''''''''''''''''
' Your code here
''''''''''''''''''''''''
MsgBox "Hello"

StartTimer ' Reschedule the procedure
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Timer event

Leave Chip's coding in a workbook module. On the ThisWorkbook sheet, place
this coding:

Private Sub Workbook_Open()
Call StartTimer
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"dhstein" wrote:

I'm setting up a timer event based on Chip Pearson's code which is shown below.
This works fine when I run the StartTimer code. I'd like to have this code
run when the workbook starts - so I tried putting the code in the
"ThisWorkbook" module - but then the timer event doesn't work. Any help is
appreciated.


Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "TheSub" ' the name of the procedure to run


Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat, _
Schedule:=True
End Sub

'This stores the time to run the procedure in the variable RunWhen, two
minutes after the current time.

'Next, you need to write the procedure that will be called by OnTime. For
example,

Sub TheSub()
''''''''''''''''''''''''
' Your code here
''''''''''''''''''''''''
MsgBox "Hello"

StartTimer ' Reschedule the procedure
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Timer event

Luke,

Thank you - that worked perfectly.

David


"Luke M" wrote:

Leave Chip's coding in a workbook module. On the ThisWorkbook sheet, place
this coding:

Private Sub Workbook_Open()
Call StartTimer
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"dhstein" wrote:

I'm setting up a timer event based on Chip Pearson's code which is shown below.
This works fine when I run the StartTimer code. I'd like to have this code
run when the workbook starts - so I tried putting the code in the
"ThisWorkbook" module - but then the timer event doesn't work. Any help is
appreciated.


Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "TheSub" ' the name of the procedure to run


Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat, _
Schedule:=True
End Sub

'This stores the time to run the procedure in the variable RunWhen, two
minutes after the current time.

'Next, you need to write the procedure that will be called by OnTime. For
example,

Sub TheSub()
''''''''''''''''''''''''
' Your code here
''''''''''''''''''''''''
MsgBox "Hello"

StartTimer ' Reschedule the procedure
End Sub


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 Jase Excel Discussion (Misc queries) 1 September 8th 08 10:22 PM
timer Steve[_9_] Excel Discussion (Misc queries) 4 January 28th 08 08:10 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 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


All times are GMT +1. The time now is 06:27 PM.

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

About Us

"It's about Microsoft Excel"