Click to See Complete Forum and Search --> : Excel in VB


February 29th, 2000, 09:54 PM
I am usings EXCEL automation control in VB6.I open two instances of excel. After using excel I set the excel sheets =nothing, workbook =nothing and excel.application =nothing.

After the code is executed only one of the excel objects go out of memory. I still see it in the Task manager, although all the 2 excel applications are closed and exited. Any suggestions?

Kyle Burns
March 1st, 2000, 08:02 AM
You could use GetObject("Excel.Application") for your second instance of Excel. I've found Excel to be not quite as Automation friendly as it could be when it come to starting and shutting down. I usually try to grab an already running Excel instance and use that if possible.

Dim fMadeByMe as Boolean
Dim oExcelApp as Excel.Application
fMadeByMe = false
set oExcelApp = GetObject("Excel.Application")
If oExcelApp is nothing then
'Excel was not already running
set oExcelApp = new Excel.Application
fMadeByMe = true 'set the flag
End If
'Do your spreadsheet stuff here and close
'your workbook
If fMadeByMe = true then
'Only close the instance of Excel
'if you made it
oExcelApp.Close
End If
set oExcelApp = nothing