I have a user that runs an app that exports reports to Excel. This app seems to open additional instances of Excel each time a report is sent (and never closes that instance again). After exporting a dozen reports, there as a dozen instances of Excel that bog down memory etc...
How can I set up a macro to kill all instances of Excel except the instance that contains the macro in question?
I see a lot of code across forums and pages and they all seem different?
For example:
Code: Select all
Public Sub CloseAllExcel()
On Error GoTo handler
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Do While xl Is Nothing
Set xl = GetObject(, "Excel.Application")
For Each wb In xl.Workbooks
wb.Save
wb.Close
Next
xl.Quit
Set xl = Nothing
Loop
Exit Sub
handler:
If Err <> 429 Then 'ActiveX component can't create object
MsgBox Err.Description, vbInformation
End If
End Sub
Code: Select all
Sub Close_Excel()
Dim strClsExl As String
strClsExl = "TASKKILL /F /IM Excel.exe"
Shell strClsExl, vbHide
if strClsExl
End Sub
I need assistance to develop some code to close all these instances except the one which stores this macro.
TX.