Hi,
I have an Excel file with user controls. The controls include a couple of drop-down boxes and a button.
The user makes some selections, then clicks the button. The VBA code in the Click event of the button creates a new Excel.Sheet object as follows:
Dim objExcel As Object
Set objExcel = CreateObject("Excel.Sheet")
This is late binding I guess.
It does some data populating using ADO & formatting with this newly created object and then saves it.
At the end of the code, I am closing this object and also setting all the objects to Nothing .
Once everything is done running, I close the generated excel file and also the main file (which I call the 'User Options' file). I close all instances of Excel. For some reason, there is an EXCEL.EXE process still running in Task Manager. My first guess was that there was memory leak in the code. I have checked the code thoroughly and have not found any leaks.
Here is the code, in general.
Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")
strConnect = "......"
Dim rsData As New ADODB.Recordset
SQL = "......"
rsData.Open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
Sheets(1).Range("B4").CopyFromRecordset rsData
rsData.Close
Set rsData = Nothing
ExcelSheet.SaveAs(fileName)
ExcelSheet.Close
Set ExcelSheet = Nothing
Can someone please help me figure out why it is leaving the Excel Process running, and what I can do about it?
Thanks.
Saad
Bookmarks