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.
I had this issue and I resolved it by putting in the Workbook_BeforeClose()
:
ThisWorkbook.saved = true
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With