Automated Excel 2003 process not exiting

  • Thread starter Craig W. Mischenko
  • Start date
C

Craig W. Mischenko

I am creating and automating an Excel application from
VB.NET 2003 on Windows XP. I have tried creating the new
instance of Excel a couple of different ways
(CreateObject vs. New Applcation) and no matter which way
I try it the Excel process does not exit until my VB.NET
application exits. For a really simple test, I tried the
following:

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

Dim myExcel As Excel.Application

'myExcel = CreateObject("Excel.Application")
myExcel = New Excel.Application
myExcel.Quit()
myExcel = Nothing
End Sub

A new Excel process is created and even after calling the
Quit method and setting the private variable to Nothing,
the Excel process remains alive until my Windows Forms
app exits. Does anyone have an explanation/solution for
this?

Regards,
Craig W. Mischenko
 
L

Lori Turner [MSFT]

Hi Craig,

When you automate Excel from .NET, it's a good practice to null and release
object references as illustrated in the following article:

PRB: Office Application Does Not Quit After Automation from Visual Studio
.NET Client
http://support.microsoft.com/?id=317109

Another option to force garbage collection and shut down Excel is to use a
separate routine for your Excel Automation, i.e.:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Test()
End Sub

Private Sub Test()
Dim myExcel As Excel.Application
'myExcel = CreateObject("Excel.Application")
myExcel = New Excel.Application
myExcel.Quit()
myExcel = Nothing
End Sub

Hope that helps,

Lori Turner
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

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