Excel VBA Compile Error in Hidden Module: How to Fix

VBA & macros · Updated November 19, 2026

An Excel VBA compile error in a hidden module usually means that code in a workbook, add-in, or other loaded VBA project is incompatible with your Excel setup or depends on a missing library. Find which file is triggering the message, then check references and compatibility; do not enable all macros or delete files at random.

What the hidden-module message means

VBA is Excel’s programming environment. A workbook or add-in can contain code organized into modules, including modules that are not shown during ordinary use. The error means Excel could not compile some code in one of those projects. Compilation is the process of checking and preparing code before it can run.

The word hidden does not, by itself, mean that the file is malicious or that Excel is concealing a virus. It can simply refer to a module in a protected VBA project, or to code belonging to an add-in that runs in the background. The dialog may identify the module, but it often does not identify the file that contains it.

This message is different from a runtime error. A compile error prevents code from being successfully prepared to run; a runtime error happens after code starts and encounters a problem while running. If the message appears as Excel starts, an add-in or startup workbook is a likely source. If it appears only when one particular file opens, start with that file.

Why it happens

The most frequent causes are a broken reference to a library, code written for another version or platform, or an outdated add-in. A VBA project might refer to a component that is no longer installed, has moved, or is registered differently on the computer. Excel may then be unable to resolve a name used by the code.

Other causes include declarations for Windows system functions that do not match 64-bit Office, obsolete controls, code that depends on a particular Office application, and a damaged or incomplete add-in installation. A workbook created for Windows can also contain code that relies on Windows-only features and therefore fails on a Mac. Updating Excel can expose old compatibility problems, though an update is not necessarily the cause.

The timing of the message is useful evidence. A startup warning points toward something Excel loads automatically. A warning when opening a specific workbook points toward that workbook or an add-in it calls. A warning after clicking a button suggests the relevant macro or control may be involved, although some projects are compiled as they load and can fail before a button is clicked.

Identify which workbook or add-in triggers it

First note when the message appears and whether it names a module. Close Excel, reopen it, and check whether the message appears before opening your usual workbook. If it does, investigate add-ins and startup files. If it appears only with one workbook, make a separate copy and use that copy for investigation.

On Windows, start Excel in Safe Mode by pressing Windows key+R, entering excel /safe, and pressing Enter. Safe Mode starts Excel with many customizations and add-ins disabled. If the error disappears there, an add-in or customization becomes more likely; Safe Mode is a diagnostic, not a repair. If it remains, the cause may be a startup file or another component that Safe Mode does not bypass.

Then check Excel’s add-in lists. In Microsoft 365 for Windows, go to File > Options > Add-ins. At the bottom, select Excel Add-ins in the Manage box and choose Go; repeat with COM Add-ins. Record which items are selected, clear a selection, restart Excel, and see whether the warning stops. Change one item at a time so you can identify the cause and restore other add-ins if needed.

  • If disabling one add-in stops the error, check its publisher’s support page for an update or compatible replacement.
  • If no add-in makes a difference, look for workbooks or add-ins Excel loads from startup folders, such as the XLSTART folder or a configured alternate startup folder.
  • If the error is limited to one workbook, test a copy with other workbooks closed and avoid saving changes over the original during diagnosis.

Excel for Mac has its own add-in controls and does not use the Windows COM add-in system in the same way. Use the add-in management options available in your Mac version, and check the add-in publisher’s instructions. The Windows excel /safe command does not apply to Mac.

Check for missing VBA references

If you can access the project, open the Visual Basic Editor. On Windows, press Alt+F11, or choose Developer > Visual Basic. On Mac, use Developer > Visual Basic; the keyboard shortcut can vary with the keyboard and macOS settings. In the editor, choose Tools > References.

Look for an entry beginning with MISSING:. This indicates that the project expects a library Excel cannot currently find. The name may refer to a component supplied by another application or a third-party product. If the missing reference is essential, install or repair the correct component, or ask the workbook’s author or add-in publisher which supported version is required.

Do not simply uncheck a missing reference and assume the project is repaired. That can help only if the code does not actually need the library, or if the project can be updated to use an available alternative. If the project is password-protected or its VBA code is inaccessible, you may not be able to inspect its references; contact the supplier instead of trying to bypass the protection.

After resolving a reference, use Debug > Compile VBAProject in the Visual Basic Editor, if that command is available. Compilation can reveal another issue after the first one is corrected. If you are not the project’s maintainer, do not edit unfamiliar code merely to make the compile command succeed.

Check Office version and 32-bit or 64-bit compatibility

Older VBA code may call Windows functions directly. Code written for 32-bit Office can need changes to work correctly with 64-bit Office. In particular, Windows API declarations may need the PtrSafe keyword, and values that store pointers or handles may need the LongPtr type. A declaration that is wrong for the current Office architecture can cause compile problems or other failures.

These changes are not a universal fix. Adding PtrSafe blindly does not guarantee that a declaration’s argument and return types are correct, and it does not make Windows-specific code work on Mac. The project maintainer should update and check the declarations for the intended Office versions and operating systems. Check your Office architecture under File > Account > About Excel on Windows; the About screen identifies whether Office is 32-bit or 64-bit.

Also consider whether the file was created in an older Excel release or uses a discontinued control or library. Ask the author which Excel versions and operating systems the project supports. If the file came from a vendor, use a current release from that vendor rather than copying code from an unrelated online fix.

Repair the source without weakening security

Once you have identified the likely source, update it from a trusted publisher or remove it through the publisher’s recommended process. For an Excel add-in, first check its documentation for an uninstall or update procedure. For a workbook, obtain a corrected copy from its owner. Keep the original file unchanged until you know the replacement works.

For a damaged Office installation, Windows users can try the repair options in Settings > Apps > Installed apps (or the equivalent Apps list in their Windows version), select Microsoft 365, choose Modify, and follow the available repair choices. The exact labels can vary by installation. Repairing Office may address damaged application components, but it will not correct defective VBA code or a missing third-party library. On Mac, use Microsoft’s current Office update and troubleshooting guidance for the installed version.

Do not respond by choosing “Enable all macros” or lowering macro security for every file. Macro security controls whether code is allowed to run; it does not repair incompatible code or a missing reference. On Windows, review File > Options > Trust Center > Trust Center Settings > Macro Settings with your organization’s policy in mind. Only open macro-enabled files from sources you trust. Organizations may manage these options centrally, and Mac controls differ by release.

How to prevent the error returning

Keep add-ins and vendor tools up to date, and confirm that a workbook’s author supports your Office version and operating system before relying on it. When moving a workbook between computers, remember that its VBA project may depend on installed libraries or controls that are not embedded in the workbook. A working file on one machine is not proof that every dependency is present elsewhere.

  • Keep an untouched backup before making changes to a macro-enabled workbook.
  • Document required add-ins and references when maintaining a VBA project.
  • Test important workbooks after Office upgrades, architecture changes, or migration to Mac.
  • Use signed or otherwise verifiable files from known publishers, and follow workplace security rules.

Macros cannot be undone with Ctrl+Z. If you need to test or edit a macro-enabled workbook, save a separate copy first and work on that copy. This is especially important if the code changes worksheets, files, or other application settings.

Frequently Asked Questions

Does a hidden-module error mean my workbook has a virus?
No. The message describes a failure to compile code in a VBA project; it does not diagnose malware. Treat an unexpected file cautiously, check its source, and scan it using your organization’s approved security tools, but do not infer that it is malicious from this error alone.

Why does the error appear when Excel starts?
Excel may be loading an add-in, a workbook in XLSTART, or a file in an alternate startup folder. Disable add-ins one at a time and check startup locations. If the message disappears after a particular item is disabled or moved, that item is a strong lead.

Can I fix the error by enabling macros?
Usually not. Enabling macros permits code to run under the applicable security settings; it does not supply a missing library or make incompatible VBA compile. Do not lower security settings for files you do not trust.

What if the VBA project is password-protected?
You may be unable to inspect its modules or references. Ask the file’s owner or publisher for an updated, supported version. If it is an organization-managed workbook, contact your IT team rather than attempting to bypass project protection.

Will reinstalling Excel solve it?
Not necessarily. Reinstalling or repairing Excel may help if Office itself is damaged, but it will not fix incompatible code, an unavailable third-party component, or an outdated add-in. Identify the file or add-in responsible first, then choose a repair that addresses that cause.

The useful first question is not how to reveal a hidden module, but which loaded project Excel cannot compile. Narrowing the error to a workbook, add-in, reference, or compatibility issue usually points to a safer and more reliable fix than changing macro security or editing code blindly.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.