VB.Net: Remove EXCEL.EXE from TaskManager Processes

baabaa_nl
baabaa_nl used Ask the Experts™
on
Hi Experts,

How can I remove the EXCEL.EXE from the process list in the TaskManager.

Because I am using a code to export data from a gridview to excel, and after executing the code, the EXCEL.EXE is still running on the Tastkmanager and when I run that code again and again it adds up the EXCEL.EXE in the process list.

Could you please give me a code to end process the EXCEL.EXE using VB.Net.

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dim app As New Excel.Application
 '... 'After doing your stuff '...
app.Quit()

more details in below link
http://stackoverflow.com/questions/5189379/how-to-end-excel-exe-process
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial