Closing Excel

B

Bill

I have inherited an App desigend by an ex employee

Sometimes the program leaves Excel in the task manager

The programe uses various routines and calling various functions that define
Excel sheets etc (badly named)

I'm finding it hard to follow (my 1st experince of .NET)

is there a way to KILL any Excel instence when exiting the program.


I have come across some posts about GC (garbage collection)
like this
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWsheet)
oXLWsheet = Nothing
'System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWs)
oXLWs = Nothing
oBook.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
-----

My problem is I don't know ALL the Sheets & Books etc that have been defined
/used
program loops about a lot

It would be nice just to do someting like

Loop Until NoMore
GetProcessByName("EXCEL")
Kill Process
END
 
J

Jim Rech

This might be more a .Net question and an Excel question. While someone
passing through here may have something to contribute, you also might want
to ask a .Net newsgroup.

--
Jim Rech
Excel MVP
|I have inherited an App desigend by an ex employee
|
| Sometimes the program leaves Excel in the task manager
|
| The programe uses various routines and calling various functions that
define
| Excel sheets etc (badly named)
|
| I'm finding it hard to follow (my 1st experince of .NET)
|
| is there a way to KILL any Excel instence when exiting the program.
|
|
| I have come across some posts about GC (garbage collection)
| like this
| System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWsheet)
| oXLWsheet = Nothing
| 'System.Runtime.InteropServices.Marshal.ReleaseComObject(oXLWs)
| oXLWs = Nothing
| oBook.Close()
| System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
| oBook = Nothing
| System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
| oBooks = Nothing
| oExcel.Quit()
| System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
| oExcel = Nothing
| GC.Collect()
| GC.WaitForPendingFinalizers()
| -----
|
| My problem is I don't know ALL the Sheets & Books etc that have been
defined
| /used
| program loops about a lot
|
| It would be nice just to do someting like
|
| Loop Until NoMore
| GetProcessByName("EXCEL")
| Kill Process
| END
|
|
 

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