Timer event

D

dhstein

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, Procedure:=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
 
L

Luke M

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

Private Sub Workbook_Open()
Call StartTimer
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

Similar Threads


Top