How can I close an active excel window from command line?


Posted by Piero on December 27, 2001 6:33 AM

I've scheduled a macro, so it starts automatically from command line (with the AutoOpen() command--thanks to Rick E!) ; but then I need to close it, from command line yet.What command should I try?
Thanks for any help!
Bye

Posted by Scott on December 27, 2001 6:41 AM

I'm not sure if I follow. You want to run a macro when you close the workbook? If so, you could use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'\Your Macro\

End Sub

You would have to do this under workbook and not under modules.

Posted by piero on December 27, 2001 7:24 AM

I'm sorry I have not managed to explain may problem properly.
This is what I need to know : the macro I've made opens a new worksheet, and then automatically closes itself, leaving only this new worksheet(which don't contains any macro).
What should I do to close this new worksheet?
I think that I must use a dos command...
Thanks!




Posted by Joe Was on December 27, 2001 7:37 AM

If you set up some pre-program or splash page to run on startup but did not build Exit code into your startup macro code, you can generally stop a running macro with the "Esc" Escape key. If this is the case I would suggest you add a control button or exit code to your startup macro, to avoid this situation.

If the escape key works and stops your macro you can code a button with:
Application.SendKeys("{ESC}")

If escape did not work post your code and we will figure out an exit code. JSW