Instance of Excel

psionman

New member
Joined
Jul 27, 2009
Messages
4
Programming Experience
Beginner
I have a forms application that is based around an Excel Workbook. I am creating an instance of Excel.Application as the application starts and need to have the workbook open until the user quits the application.

What is the recommended way of closing the Excel.Application?
 
I assume you have an application in VB.NET that deals with Excel application as an object. If this object of correct type, you should be able to call the Quit method and, after that, set the host object as Nothing. That's how I close my own instances of Excel and Word when I need to handle them from a VB program. It seems to work ok.
 
Thanks BobCat

That's what I do, but the question is when. If I put it in the Finalize procedure of the class wher I open it I get an error, so I have to place a call to the Quit procedure in the 'Close' button on my form. But if the user closes the form from the control box this doesn't get called :numbness:
 
I am not completely sure - I am a Newbie too - but I think you should not use the .Finalize method, only the .Quit method and then set host object's value to Nothing. For the other issue, it seems you should place these instructions in a Sub which handles the FormClosing event, as described on MSDN Library: FormClosing Event
 
Back
Top