killing an OnTime schedule launched from a different workbook

A

Antonio

client1 portfolio.xls workbook launches every minute the following to update
the max and min of a portfolio value that is updated with real prices. Note
that the time in an exact minute so that it is easy to know the exact time
next scheduled:

Application.OnTime TimeValue(Hour(Now) & ":" & Minute(Now)) +
TimeValue("00:01"), "max_min"

Within the same workbook I have

Public Sub kill_max_min()

Application.OnTime TimeValue(Hour(Now) & ":" & Minute(Now)) +
TimeValue("00:01"), "max_min", , False

End Sub

That kills the OnTime when needed, for example, Before_Close. Killing the
OnTime schedule is needed because otherwise the workbook opens up after
closing (Is there an easier way to avoid the automatic reopening?). It works
fine when within the same workbook.

However, a different project in a different workbook needs to close the
workbook above. Before closing, ( since the Before_Close module is not run
when closing programmatically), I need to kill the max_min scheduled. I am
using

Application.Run "'" & client(client_index) & " portfolio.xls" &
"'!kill_max_min"


It does run the kill_max_min but it gives error. Run time error 1004. Method
On Tie of object_ Application failed.

It looks like it has lost the addressing to max_min

How can it be solved? Am I complicating this unnecessarily?

Thanks,

Antonio
 
D

Dave Peterson

Why do you say that the workbook_beforeclose event doesn't fire when closing
Workbook A from workbook B?

It does for me.

In fact, the only way I know to stop it is to disableevents before I close that
workbook.

If you're doing that, is there a reason?
 
A

Antonio

Hi Dave,

Yes, you are right. Ithe workbook_beforeclose event is fired when closing
from a different workbook.



It is just, that, as you can see from my other post. The ontime does not
seem to be cancelled when run from the beforeclose.



I am not disabling events.
 

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