November 07, 2007

Office application does not quit after automation from Visual Studio .NET client


This is a common nasty problem that has bugged me a lot lately

When you automate a Microsoft Office application from Microsoft Visual Basic .NET or Microsoft Visual C# .NET, the Office application does not quit when you call the Quit method.

Here's the solution:

In your form's FormClosing event add the following code

ExcelApp.Application.Application.Quit();
ExcelApp.Application.Quit();
GC.Collect();
GC.WaitForPendingFinalizers();


Source: http://support.microsoft.com/?kbid=317109


Back to Home

1 comments:

Mike B said...

To anyone finding this in Google: This will quit the office application when your application closes, but may not before if you do not also clean up references in the RCW. In other words, there's more to it, be sure to see the KB article.

Post a Comment