Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.Quit command not closing the entire Excel Application

Tags:

excel

vba

I have following code under a button. When clicked it just closes the current Excel sheet but not the entire Excel application.

Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True
Application.Quit

Note: I don't have any other sheets open.

The following window still appears.

enter image description here

like image 445
logan Avatar asked Sep 11 '13 10:09

logan


2 Answers

I had this issue and I resolved it by putting in the Workbook_BeforeClose():

ThisWorkbook.saved = true
like image 175
FranckH Avatar answered Sep 29 '22 02:09

FranckH


remove the Application.DisplayAlerts = True from the routine.

from the help for Application.Quit Method:

If unsaved workbooks are open when you use this method, Microsoft Excel displays a dialog box asking whether you want to save the changes. You can prevent this by saving all workbooks before using the Quit method or by setting the DisplayAlerts property to False. When this property is False, Microsoft Excel doesn’t display the dialog box when you quit with unsaved workbooks; it quits without saving them.

This will avoid any (possibly hidden) prompts from stopping excel from closing completely

like image 36
SeanC Avatar answered Sep 29 '22 02:09

SeanC