Excel Cannot Edit Macro in Hidden Workbook: Fix
In this article
Excel blocks macro editing in a hidden workbook because the Visual Basic Editor (VBE) cannot open a code window for a workbook whose window is hidden. The fix is to unhide the workbook, edit the macro, then hide it again if you need it out of the way. You do not need to close other workbooks or change security settings. The steps below work in Excel for Microsoft 365, Excel 2021, 2019, and 2016 on Windows and Mac; menu labels can differ slightly by version and platform.
What You'll Need
- Excel with the workbook that contains the macro already open (even if its window is hidden).
- The workbook must not be password-protected against structure changes, or you must know that password.
- Macro security set to allow macros to run, at least for this session. If macros are disabled entirely, the VBE will not let you edit code.
- On Windows, the Developer tab visible (File > Options > Customize Ribbon > check Developer). On Mac, the Developer tab is on by default in recent versions; if not, enable it in Excel > Preferences > Ribbon & Toolbar.
Step-by-Step
- Confirm the workbook is actually hidden. In the ribbon, go to View > Unhide. If the Unhide button is greyed out, no workbook in the current Excel instance is hidden, and your problem is something else (see Troubleshooting). If the Unhide dialog lists the workbook, note its exact name and continue.
- Unhide the workbook. View > Unhide, select the workbook in the list, and click OK. The workbook window appears. Do not close it again until you have finished editing.
- Open the Visual Basic Editor. Press Alt+F11 on Windows, or Option+F11 on Mac. You can also use Developer > Visual Basic.
- Find the project. In the Project Explorer pane (left side; if it is missing, use View > Project Explorer inside the VBE), expand the VBAProject node that matches the workbook name you just unhid. Expand its Microsoft Excel Objects and Modules folders.
- Open the code module. Double-click the module or sheet object that contains the macro. The code window opens on the right.
- Edit the macro. Make your changes in the code window. If the code window is read-only (the title bar says Read Only or the text is greyed), the workbook may be open from a read-only location or marked as final. Save a copy to a writable folder and reopen it before editing.
- Compile and save. In the VBE, use Debug > Compile VBAProject to catch syntax errors, then press Ctrl+S (Cmd+S on Mac) to save. If Excel prompts that the workbook contains a VB project and asks about saving, choose Yes to keep the macro.
- Test the macro. Switch back to Excel (Alt+F11 again or click the Excel icon in the taskbar or Dock) and run the macro from Developer > Macros or the assigned button. Confirm it behaves as expected.
- Hide the workbook again if needed. In Excel, with the workbook active, go to View > Hide. The workbook disappears from the screen but stays open, and your edited macro remains available to other workbooks that call it.
Common Mistakes
- Hiding the workbook before saving. If you hide it and then close Excel without saving, the edit is lost. Save while the workbook is visible, then hide it.
- Editing the wrong project. The Project Explorer lists every open workbook. Two files with similar names (for example, Book1 and Book1 (2)) are easy to confuse. Check the project name against the workbook name in the title bar.
- Assuming View > Unhide is the only route. If the workbook was opened with its window hidden by a macro (for example,
Windows("Book1").Visible = False), View > Unhide still lists it, but you must run the unhide step from a workbook that is visible. If every workbook is hidden, Excel shows no window at all; use the Window menu inside the VBE or reopen Excel. - Forgetting the personal macro workbook. PERSONAL.XLSB is hidden by design. Unhide it the same way, edit, save, and hide it again. Leaving it visible is harmless but clutters the screen.
- Ignoring read-only status. A workbook opened from an email attachment or a protected folder opens read-only. Edits to the VBA project will not save until you copy the file to a local writable folder.
Tips
- Use the VBE's Immediate Window (Ctrl+G) to run a one-line command such as
Workbooks("YourFile.xlsm").Windows(1).Visible = Truewhen the normal Unhide route is awkward. - Before editing, make a copy of the workbook. Macro edits are easy to make and hard to undo if you overwrite a working version.
- If the macro is stored in an add-in (.xlam), the add-in itself is usually hidden. Unhide it, edit, save, then hide again; otherwise the add-in may unload on restart.
- Keep the Developer tab visible while you work so you can reach Visual Basic, Macros, and Macro Security without hunting through menus.
- If you only need to run the macro, not edit it, you do not need to unhide anything. Hidden workbooks can still run their macros when called from another workbook.
Troubleshooting
If View > Unhide is greyed out, no workbook is hidden in that Excel instance, or the hidden workbook belongs to a different instance. Close extra Excel windows, then reopen the file that contains the macro.
If the VBE opens but the project is missing, the workbook may be open in another Excel instance. Close the other instance or open the file in the same window.
If the code window is read-only, check the file's location and properties. Copy it to your Documents folder, clear the read-only attribute in File Explorer (right-click > Properties) or Finder (Get Info), and reopen.
If changes will not save, the workbook may be protected. Review > Protect Workbook and Review > Protect Sheet can block structural changes; unprotect with the password if you have it. If you do not, you cannot edit that project.
If macros are disabled by policy, Developer > Macro Security may be greyed out. In that case the setting is controlled by your organisation and you cannot change it locally; contact your IT administrator.
If Excel crashes when you unhide, start Excel in safe mode (hold Ctrl while launching on Windows; hold Shift while launching on Mac) and try again. Safe mode disables add-ins, which can conflict with hidden workbooks.
Frequently Asked Questions
Why can't I edit a macro in a hidden workbook?
The VBE needs a visible window to host the code editor for that project. A hidden workbook has no window, so Excel blocks editing until you unhide it.
Can I run a macro from a hidden workbook?
Yes. Hidden workbooks can still execute their macros when called from another workbook or from the Macros dialog, as long as macros are enabled.
Does unhiding the Personal Macro Workbook break anything?
No. PERSONAL.XLSB is hidden only to keep it out of the way. Unhide it, edit, save, and hide it again; your macros continue to work.
What if the Unhide option is greyed out?
That means no workbook in the current Excel instance is hidden. The file may be open in a different Excel instance, or the window may be minimised rather than hidden.
Can I edit a macro in a read-only workbook?
No. Save a copy to a writable location, clear the read-only attribute, and reopen the copy before editing.
Do I need the Developer tab to fix this?
Not strictly. Alt+F11 (Option+F11 on Mac) opens the VBE without the Developer tab, and View > Unhide is on the standard ribbon. The Developer tab just makes the tools easier to find.