MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Excel VBA (Ending A Process)


Posted by Dave on February 14, 2002 8:15 PM

I am using VB6 and excel 2000.
After I exit excel from a VB form with application.quit, the excel Process still runs.
If I try to re-open excel within VB excel will not open properly and is unusual. The excel process will only remove itself after the VB form is closed.

How do you get rid of the excel process after when you quit?


Posted by Ivan F Moala on February 15, 2002 2:15 AM

Try destroying the application.
With some Automation Servers, setting an object variable to Nothing doesn’t necessarily close the server application. If you're using the CreateObject function to create an instance of an Automation Server, be sure to use a method defined by the Server to quit it if possible and then set the object variable to Nothing. If not, your code may be leaving multiple sessions of the Automation server open. This is very common when automating Microsoft Excel, for instance.

' quit the application object
xlApp.Quit

' destroy the object
Set xlApp = Nothing


Ivan

Posted by Dave on February 15, 2002 7:16 AM

Thanks for the help. I should have placed my code in the message so you could see what steps I took to get there. I tried dumping the process by setting the object to nothing, but still no luck. Below is the code:

Dim excelapp as excel.application
Set ExcelApp = GetObject("Excel.Application")
If ExcelApp Is Nothing Then
Set ExcelApp = CreateObject("Excel.Application")

If ExcelApp Is Nothing Then
MsgBox "Excel Could Not Be Opened"
End
End If
End If
Set ExcelFile = Workbooks.Open(“c:\filename.xls”)

Excelapp.quit
Set excelapp = nothing

I am open for any suggestions.

Thanks