Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Cancelling Application.OnTime

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Cancelling Application.OnTime

On Jul 11, 12:58 am, Dan wrote:
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


Hello Dan,

This should help. It is from the VBA help file...

OnTime Method Example

This example runs my_Procedure 15 seconds from now.

Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"
This example runs my_Procedure at 5 P.M.

Application.OnTime TimeValue("17:00:00"), "my_Procedure"
This example cancels the OnTime setting from the previous example.

Application.OnTime EarliestTime:=TimeValue("17:00:00"), _
Procedu="my_Procedure", Schedule:=False

Sincerely,
Leith Ross

  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Cancelling Application.OnTime

Hi,
Thanks, but that is exactly my question - I have access to this page too,
and I copied it but as per my question this is not working and this was what
I was asking.

"Leith Ross" wrote:

On Jul 11, 12:58 am, Dan wrote:
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


Hello Dan,

This should help. It is from the VBA help file...

OnTime Method Example

This example runs my_Procedure 15 seconds from now.

Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"
This example runs my_Procedure at 5 P.M.

Application.OnTime TimeValue("17:00:00"), "my_Procedure"
This example cancels the OnTime setting from the previous example.

Application.OnTime EarliestTime:=TimeValue("17:00:00"), _
Procedu="my_Procedure", Schedule:=False

Sincerely,
Leith Ross


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Cancelling Application.OnTime

You need to pass the EXACT time of the timer back to OnTime in order to
cancel the timer. Therefore, you should create a public variable outside of
any procedure and store the time in that variable.

Public RunWhen As Double

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

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

See http://www.cpearson.com/excel/ontime.aspx for full details.


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


"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


  #5   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Cancelling Application.OnTime

Thank you very much

"Chip Pearson" wrote:

You need to pass the EXACT time of the timer back to OnTime in order to
cancel the timer. Therefore, you should create a public variable outside of
any procedure and store the time in that variable.

Public RunWhen As Double

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

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

See http://www.cpearson.com/excel/ontime.aspx for full details.


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


"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




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
Help with Application.OnTime [email protected] Excel Programming 1 April 3rd 06 06:02 PM
Application OnTime...need some help to schedule. wayliff[_14_] Excel Programming 1 January 19th 06 07:47 PM
application.ontime rick Excel Programming 2 July 25th 05 06:09 PM
OnTime Unusual Application Peter[_52_] Excel Programming 4 January 19th 05 05:59 AM
Application.OnTIme Mike Excel Programming 8 September 15th 04 03:27 PM


All times are GMT +1. The time now is 02:51 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"