0
votes

I have a macro in Outlook that calls an Excel file and runs a macro in that Excel file then closes the file. The problem is After closing Excel it stays in the Task Manager. I have tested this a million times and I even have removed all code in my Excel macro to see if that was the problem but Excel is still is still getting stuck in the task manager. My Outlook code is:

Dim xlApp As Object
Dim xlWB As Workbook
Dim strFile As String
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True
xlApp.DisplayAlerts = False
strFile = "c:\desktop\a.xlsm"
Set xlWB = Workbooks.Open(strFile)
xlApp.Run ("Cleanup")
xlWB.Close False
If Not xlWB Is Nothing Then
    Set xlWB = Nothing
End If
xlApp.Quit
If Not xlApp Is Nothing Then
    Set xlApp = Nothing
End If
1
Remove the if not <whatever> is Nothing tests, to start. If either of them is Nothing at that point, your code would have broken far before that point; the tests to see if they're Nothing before setting them to Nothing is simply useless clutter. - Ken White
Does the excel process still appear in the task manager after you've quit outlook too? - SierraOscar
If you comment out xlApp.DisplayAlerts = False, does it get you any alert messages? - user6432984
Are you sure they (EXCEL.EXE) are the same process that runs the code? I have just tested that when Excel Previewer is enabled in Outlook and one of the excel attachments are previewed then moved away from it, the EXCEL.EXE remains in Task Manager (with the option /Embedding in the Command Line. The xlApp here should have /automation. Is that the case? - PatricK
Thanks for all the replies! I have removed if not is nothing. Excel closes after closing outlook in the task manager. If I comment out the displayalerts I usually do not get any messages, I just have it there in case excel randomly gets stuck in read only. Commenting it out doesn't stop Excel from getting stuck in the task manager. PatricK I don't believe I understand your response. I removed calling the macro in Excel and Excel still gets stuck in the task manager. - Schwimms

1 Answers

0
votes

The problem with the code was that I was not opening the workbook with the Excel application that I created. I fixed the problem by adding xlApp here:

Set xlWB = xlApp.Workbooks.Open(strFile)

That could have not been a more simple fix to such a time consuming problem :(