Close a running application

A

Amjad

I have a program that updates an Excel sheet everytime
the user presses a button. However, each time it creates
a new instance of the Excel.exe application running in
the background.
I tried closing my Excel object (oExcel) using the
following:
oExcel = Nothing
oExcel.quit()

Yet, I still can see an instance of Excel.exe in the
Windows Task Manager Processes.

Any idea on how to force this application to terminate
once I'm done with it?

Note1: I define the Excel object using:

Dim oExcel As Excel.Application
oExcel = CType(CreateObject("Excel.Application"), _
Excel.Application)

Note2: When I end my program, that instance of Excel
disappears. I wish to see that without leaving my program.
 
H

Herfried K. Wagner [MVP]

* "Amjad said:
I have a program that updates an Excel sheet everytime
the user presses a button. However, each time it creates
a new instance of the Excel.exe application running in
the background.
I tried closing my Excel object (oExcel) using the
following:
oExcel = Nothing
oExcel.quit()

Yet, I still can see an instance of Excel.exe in the
Windows Task Manager Processes.

Any idea on how to force this application to terminate
once I'm done with it?

Note1: I define the Excel object using:

Dim oExcel As Excel.Application
oExcel = CType(CreateObject("Excel.Application"), _
Excel.Application)

Note2: When I end my program, that instance of Excel
disappears. I wish to see that without leaving my program.

\\\
System.Runtime.InteropServices.Marshal.ReleaseComObject(App)
App = Nothing

' Perhaps you need these lines too:
GC.Collect()
GC.WaitForPendingFinalizers()
///
 
A

Amjad

Hi..
Thanks for your reply, but the problem hasn't been solved
yet! (Excel.exe is still running in the background)
Any other suggestions?

Amjad
 
F

Fergus Cooney

Hi Amjad,

You may have to do the same sort of releasing on <all> of the Excel
objects that you create.

Next year's .NET will include better Office integration. Perhaps they will
have addressed this issue.

In the meantime, the interop newsgroup is possibly the best place for this
question as they must have been asked it a hundred times for Excel and all the
other Office products.
news://msnews.microsoft.com/microsoft.public.dotnet.framework.interop

Regards,
Fergus
 

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