To close the VBA Editor in Excel, click the standard X in the top-right corner of the VBA Editor window (or press Alt+Q while the Editor is the active window). If your code has unsaved changes, a dialog will ask whether you want to save before it closes. Closing the Editor does not close your workbook or quit Excel — it only hides the code window and returns you to the spreadsheet. If you want to close Excel entirely, close the VBA Editor first as described below, then close the workbook.

A quick note on wording: button and menu labels can differ slightly by Excel version, device and region, so if a label you see is not worded exactly as written here, look for the closest equivalent.

What You'll Need

  • Microsoft Excel for Windows or Mac with the Developer tab enabled, or any workbook that contains macros.
  • Your workbook open (the VBA Editor cannot be opened on its own).
  • A decision on whether you need to keep any code you have typed since the last save.

You do not need any special permissions to close the Editor. However, if the workbook itself is protected or the VBA project is password-protected, saving code changes may need that password.

Step-by-Step

  1. Save your code intentionally, not by accident. Before closing, look at the title bar of the VBA Editor. If a project has unsaved edits, the file name usually shows an indicator. Click File > Save in the VBA Editor (or press Ctrl+S on Windows, Cmd+S on Mac) while the Editor is active. Doing it now means the closing dialog has nothing to catch you on.
  2. Make the workbook window active if you want to avoid the exit question. If your goal is simply to get back to the sheet, you can click anywhere on the Excel window behind the Editor. On Windows, pressing Alt+F11 toggles between the Excel window and the VBA Editor, which is often faster than clicking.
  3. Close the Editor with the X. Click the close button in the top-right corner of the VBA Editor window (top-left on Mac). The Editor closes and Excel comes to the front.
  4. Or use the keyboard shortcut. With the VBA Editor as the active window, press Alt+Q on Windows. On Mac, use Cmd+Q only if the Editor is a separate window — otherwise that shortcut may quit Excel itself, so prefer the red close button on the Editor window.
  5. Answer the save prompt. If a message appears asking whether to save, choose Yes to keep your edits or No to discard them. Choosing No discards everything typed since the last save in that project — there is no undo for this.
  6. Confirm you are back in the workbook. You should see your spreadsheet and the normal ribbon. If the Editor window is still visible, it is probably behind another window or minimized — check the taskbar (Windows) or the Window menu (Mac).
  7. Save the workbook if you changed code. Macro code lives inside the workbook file. Press Ctrl+S in Excel so the saved code is written to the file. For macro-enabled workbooks, keep the .xlsm format; saving as plain .xlsx will strip the macros.

Closing the Editor vs. Closing Excel

People often say "close the VBA Editor" when they actually want Excel to shut down and it refuses. Quitting Excel while the Editor is open can leave the Editor window lingering or make Excel appear not to close. Close the Editor first, then close the workbook window, then quit Excel.

On Windows, if Excel seems stuck with no visible windows, check the taskbar for a stray VBA Editor window and close that. On Mac, Excel and the Editor can behave as separate windows, so close the Editor window explicitly rather than quitting the whole application.

Common Mistakes

  • Clicking No on the save prompt by reflex. That silently throws away the code you just wrote. Read the prompt before answering.
  • Saving as .xlsx. Excel will warn that macro-free formats cannot store VBA, but if you click through, the code is gone from the file on the next open.
  • Thinking closing the Editor removes macros. It does not. The Editor is just a code window; the macros stay in the workbook. To remove them, you would delete the modules in the Editor itself.
  • Using Alt+Q in the wrong window. In the Excel window, Alt+Q usually jumps to the Search/Help box rather than closing anything. Shortcuts depend on which window is active.
  • Leaving code with a compile error. Unsaved or erroring code is saved with the file and can pop up error dialogs when the workbook opens. Run Debug > Compile VBAProject before closing if you have been editing.

Tips

  • Use Alt+F11 as your toggle between the spreadsheet and the Editor — it is quicker than closing and reopening.
  • If the closing prompt keeps catching you, get in the habit of pressing Ctrl+S (Cmd+S on Mac) in the Editor after every meaningful change.
  • Name your modules clearly so, if the save prompt lists projects, you know what you are keeping or discarding.
  • Close extra code windows you no longer need with the X on each window's tab or title bar to reduce clutter before you exit.
  • If you are handing the file to someone else, close the Editor and save first so the file arrives in a clean, consistent state.

Troubleshooting

The close button does nothing. A modal dialog may be waiting behind the Editor, or the code is paused in break mode. In the Editor, press Debug > Reset (the stop square on the toolbar) to end execution, then try closing again.

Excel will not quit. Close the VBA Editor first, then the workbook, then Excel. If Windows Task Manager shows Excel still running with no window, end the task there — but save your work first, because anything unsaved is lost.

The save prompt appears repeatedly. Something is modifying the project, often an add-in or an event macro firing on Workbook events. Close the Editor without saving, reopen it, and check whether a module is changing automatically. If the workbook has a password-protected VBA project and you do not know the password, you cannot save code changes — closing without saving is the safe option.

You closed and your macros seem missing. Reopen the workbook with macros enabled. If Excel shows a security warning bar, click Enable Content; macros stay disabled until you do, and disabled macros can look like missing code.

If that did not work, close Excel completely, reopen the file, and check File > Options > Trust Center settings if macros still do not appear. Do not disable security features globally just to see code — adjust only the specific trusted location you need.

Frequently Asked Questions

Does closing the VBA Editor delete my macros?

No. Closing the Editor only closes the code window. The macros remain in the workbook as long as you save the file in a macro-enabled format.

What is the keyboard shortcut to close the VBA Editor?

On Windows, Alt+Q closes the Editor when it is the active window. On Mac, use the red close button on the Editor window; quitting with Cmd+Q may quit Excel instead.

Why does Excel ask to save when I close the Editor?

Because your VBA project has changes that are not yet saved. Choose Yes to keep them or No to discard them.

Will closing the Editor stop a macro that is running?

Not necessarily. A running macro can block the Editor from closing, or the code may still be executing. Press Debug > Reset before closing.

Can I close the Editor without saving?

Yes. Answer No to the save prompt. Everything typed since the last save in that project is discarded and cannot be recovered.

Does closing the Editor close Excel too?

No. They are separate actions. Close the Editor, then the workbook, then Excel if you want to quit the program.