Detecting an orphaned Excel.Application

P

Phil Hibbs

I sometimes create an Excel.Application object, and use that to open
another workbook, read the contents, then close and quit it. If my
code crashes or if I interrupt it, the application object stays
running and still has the workbook open. The only way that I have of
tidying this up is to close any other Excel spreadsheets that I have
open and quit out, then open a spreadsheet by double-clicking on it,
this will make Excel notice that there is an Excel application object
already running and re-use that to open the workbook, and then I can
see that it has another workbook already open, and I can quit it.

Is there any other way to detect a hidden Excel application instance
that is running hidden, and specifically direct it to close? Other
than running Task Manager and forcing EXCEL.EXE to close, I mean, is
there anything I can do within an Excel macro to tidy it up?

Phil Hibbs.
 
J

JP

The first thing to do would be to add an error handler that closes the
running Excel instance if an error occurs. That would handle the cases
where the code causes an error.

The other thing to do would be to use FindWindow and FindWindowEx APIs
to see if you can grab the Excel window (as you expect it to exist).

--JP
 

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