I saw a lot of suggestions on this issue, and I tried all of them, but no one seems to work. The VBA code is in a product other than Microsoft (SAP Business Objects, which may be a problem). I create an Excel object:
Set oExcel = CreateObject("Excel.Application")
Download the contents from column 1 of one of the worksheets into a separate workbook, then close Excel. Each time he leaves the process in memory, occupying 5 mb of memory.
I tried to make the oExcel object visible, so at least I could kill it without resorting to the task manager, but when I invoke Quit, the user interface exits and still leaves the process.
Each time I run the code, it creates a new process. So I tried to reuse any existing Excel processes by calling
Set m_oExcel = GetObject(, "Excel.Application")
and only creating it if this call returns nothing,
This did not propagate the processes, but each process grew by 5+ mb each time, so essentially the same problem.
In each case, I close the open book and set DisplayAlerts to False before exiting:
m_oBook.Close SaveChanges:=False m_oExcel.DisplayAlerts = False m_oExcel.Quit
This bit of code has been used for at least five years, but this problem did not occur until we moved to Windows 7.
Here is the complete code if it helps. Note that all Excel objects are module level variables (prefix "m_") per sentence, and I used the "one point" rule for another sentence. I also tried using shared objects (i.e. Late restrictions), but this also did not help solve the problem:
Private Function GetVariablesFromXLS(ByVal sFile As String) As Boolean On Error GoTo SubError If Dir(sFile) = "" Then MsgBox "File '" & sFile & "' does not exist. " & _ "The Agent and Account lists have not been updated." Else Set m_oExcel = CreateObject("Excel.Application") Set m_oBooks = m_oExcel.Workbooks Set m_oBook = m_oBooks.Open(sFile) ThisDocument.Variables("Agent(s)").Value = DelimitedList("Agents") ThisDocument.Variables("Account(s)").Value = DelimitedList("Accounts") End If GetVariablesFromXLS = True SubExit: On Error GoTo ResumeNext m_oBook.Close SaveChanges:=False Set m_oBook = Nothing Set m_oBooks = Nothing m_oExcel.DisplayAlerts = False m_oExcel.Quit Set m_oExcel = Nothing Exit Function SubError: MsgBox Err.Description GetVariablesFromXLS = False Resume SubExit ResumeNext: MsgBox Err.Description GetVariablesFromXLS = False Resume Next End Function