To close Excel from VBA, use Application.Quit. If your code lives in the same workbook, save first with ThisWorkbook.Save (or ActiveWorkbook.Save) and then call Application.Quit. If unsaved changes exist, Excel will prompt the user unless you set Application.DisplayAlerts = False before quitting — and you must set it back to True if the code continues. That is the shortest working answer. The rest of this guide covers the safe patterns, the difference between closing a workbook and quitting the application, and the mistakes that leave orphaned Excel processes running in Task Manager.
What You'll Need
- Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer). Menu labels can differ slightly by version and region.
- A workbook that contains macros (.xlsm) or an add-in, since standard .xlsx files cannot store VBA.
- Basic familiarity with the VBA editor (Alt+F11) and the Immediate Window (Ctrl+G).
- Administrator rights are not required, but you should know how to open Task Manager to check for leftover EXCEL.EXE processes.
Step-by-Step
- Open the VBA editor. Press Alt+F11 in Excel. In the Project Explorer, find your workbook and insert a module (Insert > Module) or open an existing one.
- Decide what you actually want to close. Closing a workbook removes that file from Excel but leaves the application running. Quitting the application closes every open workbook and ends the Excel process. Use
ThisWorkbook.Closewhen you only need to close one file; useApplication.Quitwhen the whole Excel instance should end. - Save before you quit. Add
ThisWorkbook.Savebefore the quit line. If the workbook is new and has never been saved,Savewill raise an error — useThisWorkbook.SaveAswith a full path first, or checkThisWorkbook.Pathand skip saving when it is empty. - Suppress prompts only when you mean to. Insert
Application.DisplayAlerts = Falsebefore the quit call so Excel does not ask about unsaved changes. Set it back toTrueimmediately after if any code runs afterwards. Leaving it False affects the whole Excel session, not just your macro. - Call Quit. Write
Application.Quiton its own line. If other workbooks are open with unsaved changes, Excel may still prompt or refuse depending on how alerts are set and whether the workbooks were opened read-only. - Release object references. If your code created Excel objects (for example via
CreateObject("Excel.Application")from another Office app), set them toNothingafter quitting:Set xlApp = Nothing. This is the most common cause of a hidden EXCEL.EXE process that never disappears. - Test from a copy. Run the macro on a duplicate workbook first. Quitting Excel while your own macro is still executing can terminate the code mid-run, so place
Application.Quitas the last executable line in the procedure. - Verify the process ended. Open Task Manager (Ctrl+Shift+Esc), go to the Details tab, and look for EXCEL.EXE. If it remains after the window closed, you have an unreleased reference or a hidden instance — see Troubleshooting.
Common Mistakes
- Using Quit when Close was intended.
Application.Quitcloses every open workbook, including ones the user did not save. For a single file, useThisWorkbook.Close SaveChanges:=True. - Forgetting to reset DisplayAlerts. If the macro errors after setting it to False, alerts stay off for the rest of the session and users stop seeing overwrite and save prompts.
- Quitting from a workbook-level event. Calling Quit inside
Workbook_BeforeCloseorWorkbook_Opencan create loops or kill the macro before it finishes. Keep Quit in a normal module procedure. - Not releasing external references. When one Office app automates Excel, every Excel object must be set to Nothing. A single lingering reference keeps the process alive invisibly.
- Saving a never-saved workbook with Save.
Savefails on an unsaved workbook; checkPathor useSaveAs. - Assuming Quit always closes instantly. If a modal dialog or a protected-view prompt is open, Quit waits. Close dialogs first.
Tips
- Wrap the quit sequence in error handling so DisplayAlerts is restored even if something fails: use
On Error GoTo Cleanupand putApplication.DisplayAlerts = Truein the cleanup block. - For automation from Word, Outlook or Access, create the Excel instance, do the work, call
xlApp.Quit, thenSet xlApp = NothingandSet xlBook = Nothingin that order. - Use
Application.Workbooks.Countto check whether other workbooks are open before quitting, so you do not surprise the user. - If you only need to close the current file and keep Excel open,
ThisWorkbook.Close SaveChanges:=Falseis the clean one-liner. - Keep a backup of any workbook that a macro will quit, because unsaved changes are lost when alerts are suppressed.
Troubleshooting
Excel closes but EXCEL.EXE stays in Task Manager. This almost always means an object reference was not released. Find every variable that holds an Excel object and set it to Nothing after Quit. If the macro is in the same workbook, this is less common, but add-in code or COM add-ins can also hold the process open. Disable add-ins temporarily to isolate the cause.
The macro stops before Quit runs. Check for a runtime error above the quit line. Add On Error GoTo Cleanup and a message box in the cleanup block so you can see what failed.
Excel prompts to save even though you set DisplayAlerts to False. Some prompts, such as those from protected view or from a workbook opened read-only, are not suppressed by DisplayAlerts. Close those workbooks explicitly first.
Quit does nothing. A modal dialog may be waiting. Switch to Excel and dismiss any message box, then run the macro again. Also confirm the line is spelled Application.Quit and is not inside a commented block.
You cannot reopen Excel after quitting. Wait a few seconds; the process may still be shutting down. If it persists, end the EXCEL.EXE task in Task Manager, then reopen. Ending the task discards unsaved changes, so save first whenever possible.
Frequently Asked Questions
What is the difference between Workbook.Close and Application.Quit?
Close removes one workbook from Excel and leaves the application running. Quit ends the Excel application and closes all open workbooks.
How do I close Excel without saving changes?
Set Application.DisplayAlerts = False, call Application.Quit, then set DisplayAlerts back to True. Unsaved changes are discarded, so use this only when you are certain.
Why does EXCEL.EXE remain after my macro quits?
An Excel object reference was not set to Nothing, or an add-in is holding the process. Release all object variables and test with add-ins disabled.
Can I quit Excel from a workbook event?
It is possible but risky. Quit inside BeforeClose or Open can interrupt the macro or cause loops. Put Quit in a standard module procedure instead.
Does Application.Quit work in Excel for Mac?
Yes, the VBA object model is largely the same, though some prompt behaviour and file paths differ. Test on the target platform.
How do I close only the active workbook?
Use ActiveWorkbook.Close SaveChanges:=True or False depending on whether you want to save. This leaves Excel and other workbooks open.