Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Application.Quit" leaves Excel running in the background

I have a small excel file that is launched by a scheduling app every 15 minutes.

Functions in the excel cells read data from various places on the network and stores it in cells in this excel file. That all works perfectly.

VBA code then saves the file and does an Application.Quit.

In the previous version of excel, it worked great. Since upgrading to 2016, Application.Quit closes the "excel interface" but Task manager shows a hundred "Excel.exe"'s still sitting there using up 40MB of memory each.

The attached picture shows only five excel.exe's in Task Manager since the computer had only been running less than two hours at this point. But after 24 hours there are about 100 of them. So the computer crashes within a few days.

Excel.exe still running


Thanks for the speedy assistance. I'm not sure if I'm supposed to put my responses here by editing my original question.

Here is the code. The actual updating of cell values is performed in the cells themselves. There is an Add In that reads values from some PLCs in our factory. That all works fine.

Private Sub Workbook_Open()
    Application.CalculateFull
    ActiveWorkbook.Save
    Application.Quit
End Sub

When the excel file it launched, it updates and closes. This has worked for many years until we upgraded to 2016. Application.Quit would make excel go away completely. Not now.

like image 332
Davidfox789 Avatar asked Mar 23 '18 13:03

Davidfox789


2 Answers

Before Excel 2016, Excel had the possibilities to have multiple Excel files in a single window.

In Excel 2016, it is one window per application.

The problem with your code is that it closes an instance. Based on the fact how the Excel files were opened, this would be either enough or not. E.g., if Excel files were opened in the same instance this would be quite enough.

like image 108
Vityata Avatar answered Nov 15 '22 07:11

Vityata


A bit of an amateur myself and I realize this is a bit of an old thread, but I am wondering if you save the workbook (as you do) but also close the workbook and quit Excel, it may clear up the task manager. I notice you save the workbook but don't actually close the workbook, so it stays open. I ran into a similar issue before and I think this finally what fixed it.

This is code I use every time I want to quit Excel. Usually I have 2 books open, one is a template (which I don't save) and the other is one that was created with data from the template.

ActiveWorkbook.Close SaveChanges:=True
Application.Quit
ActiveWorkbook.Close SaveChanges:=False
like image 28
Chris Murrell Avatar answered Nov 15 '22 07:11

Chris Murrell