Clear events scheduled with Ontime method

G

Guest

I need proc_2 to run a minute after proc_1 is finished. However, if proc_1
is run again less than a minute after the first time, I don't want it to run
until a minute after the second run:

ie proc_1 is trigered at 12:00:00, then again at 12:00:20
proc_2 runs once onl at 12:01:20

sub proc_1
'other code
application.ontime now+timevalue("00:01:00"), "proc_2")
end sub
sub proc_2
beep
application.statusbar = false
end sub
 
B

Bob Phillips

Try cancelling it first

Dim nTime

Sub proc_1()
On Error Resume Next
Application.OnTime nTime, "proc_2", , False
On Error GoTo 0
nTime = Now + TimeValue("00:01:00")
Application.OnTime nTime, "proc_2"
End Sub

Sub proc_2()
Beep
Application.StatusBar = False
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
T

Tushar Mehta

Option Explicit

Dim Proc2Time As Date
Sub Proc1()
On Error Resume Next
Application.OnTime Proc2Time, "Proc2", Schedule:=False
On Error GoTo 0
Proc2Time = Now() + TimeSerial(0, 1, 0)
Application.OnTime Proc2Time, "Proc2", Schedule:=True
End Sub
Sub Proc2()
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

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

Top