ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cancelling Application.OnTime - error message (https://www.excelbanter.com/excel-programming/393098-cancelling-application-ontime-error-message.html)

dan

Cancelling Application.OnTime - error message
 
Hi,
I need to run a process repeatively, but I need to be able to stop it too or
change the timing , but keep getting the following error when trying to stop
the process " Run-Time error '1004': Method 'ONTIME' of Object 'Application'
Failed"

Any idea why, or how I should do it instead.
Many thanks

Sub RunMacro()
Application.OnTime Now + TimeValue("00:00:05"), "OnTimeMacro"

End Sub

Sub OntimeMacro()
MsgBox "hello"
RunMacro

End Sub

Sub byebye()
Application.OnTime EarliestTime:=TimeValue("00:00:05"),
Procedu="my_Procedure", Schedule:=False ' this is where I keep getting
the error?
MsgBox "Bye Bye"
End Sub


Bob Phillips

Cancelling Application.OnTime - error message
 
What you need to do is save the scheduled time in a public variable, and use
that when stopping it.

Public nTime as Double

Sub RunMacro()
nTime = Now + TimeValue("00:00:05")
Application.OnTime nTime, "OnTimeMacro"

End Sub

Sub OntimeMacro()
MsgBox "hello"
RunMacro

End Sub

Sub byebye()
Application.OnTime EarliestTime:=nTime, Procedu="my_Procedure",
Schedule:=False
MsgBox "Bye Bye"
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Dan" wrote in message
...
Hi,
I need to run a process repeatively, but I need to be able to stop it too
or
change the timing , but keep getting the following error when trying to
stop
the process " Run-Time error '1004': Method 'ONTIME' of Object
'Application'
Failed"

Any idea why, or how I should do it instead.
Many thanks

Sub RunMacro()
Application.OnTime Now + TimeValue("00:00:05"), "OnTimeMacro"

End Sub

Sub OntimeMacro()
MsgBox "hello"
RunMacro

End Sub

Sub byebye()
Application.OnTime EarliestTime:=TimeValue("00:00:05"),
Procedu="my_Procedure", Schedule:=False ' this is where I keep getting
the error?
MsgBox "Bye Bye"
End Sub




dan

Cancelling Application.OnTime - error message
 
Thank you very much

"Bob Phillips" wrote:

What you need to do is save the scheduled time in a public variable, and use
that when stopping it.

Public nTime as Double

Sub RunMacro()
nTime = Now + TimeValue("00:00:05")
Application.OnTime nTime, "OnTimeMacro"

End Sub

Sub OntimeMacro()
MsgBox "hello"
RunMacro

End Sub

Sub byebye()
Application.OnTime EarliestTime:=nTime, Procedu="my_Procedure",
Schedule:=False
MsgBox "Bye Bye"
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Dan" wrote in message
...
Hi,
I need to run a process repeatively, but I need to be able to stop it too
or
change the timing , but keep getting the following error when trying to
stop
the process " Run-Time error '1004': Method 'ONTIME' of Object
'Application'
Failed"

Any idea why, or how I should do it instead.
Many thanks

Sub RunMacro()
Application.OnTime Now + TimeValue("00:00:05"), "OnTimeMacro"

End Sub

Sub OntimeMacro()
MsgBox "hello"
RunMacro

End Sub

Sub byebye()
Application.OnTime EarliestTime:=TimeValue("00:00:05"),
Procedu="my_Procedure", Schedule:=False ' this is where I keep getting
the error?
MsgBox "Bye Bye"
End Sub






All times are GMT +1. The time now is 08:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com