Q:

How to end excel.exe process?

i m trying to get excel sheet-name of a excel file from vb.net 3.5 however it opens but excel.exe still remains in the process. How do i stop the process without killing the excel.exe from task manager?
i realise new excel.application starts new process.
i tried to use quit, close and dispose.......................nothing worked
Below is my code
   Dim sheetName As New Excel.XlSheetType
   Dim newExcell As New Excel.Application
   Dim newWorkBook As Excel.Workbook = app.Workbooks.Open(MyFileName)
   Dim worksheetName As String
   Dim ws As Excel.Worksheet = CType(WB.Worksheets.Item(1), Excel.Worksheet)
    worksheetName = ws.Name

I cannot use kill because there are other excel application running, so how do i close this particular excel.exe from processor. Please help

A:

This KB article describes the problem.
However, it's not an easy one to solve, as you must ensure you call Marshal.ReleaseComObject on every Excel object you instantiate - and it's very easy to miss one.
For example, the following code implicitly references a Workbooks object:
Dim newWorkBook As Excel.Workbook = app.Workbooks.Open(MyFileName) 

To release the Workbooks object you need to reference it explicitly, so that you have a reference on which you can call Marshal.ReleaseComObject:
Dim objWorkbooks As Excel.Workbooks = app.Workbooks
Dim newWorkbook As Excel.Workbook = objWorkbooks.Open(MyFileName)
...
Marshal.ReleaseComObject(objWorkbooks)
Marshal.ReleaseComObject(newWorkbook)
...

You also should use Try/Finally to ensure ReleaseComObject is called even if an exception is thrown.

