Fix: Compile Error in Hidden Module in Microsoft Excel VBA
The “Compile error in hidden module” error occurs when you open a VBA project in Microsoft Excel. It occurs when a module used in the project is hidden or protected or if the code written in Microsoft Excel is not targeting your application’s architecture. For instance, the excel file you are trying to open is targeting a 32-bit application, but you are trying to open it in a 64-bit version.
In this guide, we’ll provide instructions on how to fix this error.
Solution 1: Unprotect the VBA code module
If you are an owner and have access to the VBA code, then unprotect the module and check if the error persists. To unprotect the module, follow these steps:
- Open Microsoft Excel, click on the Developer tab from the top, and then click Visual Basic from the left.
- If you don’t see a Developer option on the top, click on File and select Options from the left pane.
- Click on Customize Ribbon from the left pane.
- Under the Main Tabs, tick Developer and click OK to save the changes.
- Now click on Developer and Visual Basic.
- Right-click the module you want to unprotect and then select VBAProject Properties.
- Go to Protection, remove the password, confirm the password, then click OK.
- Once done, now try to run the VBA code to check if the issue is fixed.
However, If you don’t have access, you’ll have to contact the owner of the Excel document to unprotect the VBA code.
Solution 2. Uncheck Missing References
Missing references in Microsoft Excel’s VBA Project can also cause “Compile error in hidden module” error. These references. These references are links to other modules or libraries, or external files (such as 2Dshape, FixDynamics object, ActiveX control), that the VBA code in your project relies on, but are not currently available.
- Open the VBA Excel, click on the Developer tab and then click Visual Basic to open the VBA editor.
- Click on Tools and click References from the options.
- Now find the references that start with the Missing word.
- If you find them, uncheck them one by one and click OK.
- Once done, check if the error is fixed.
Solution 3. Deselect Excel Add-ins
Third-party excel add-ins can enhance functionality of Excel. However, if these add-ins are incompatible with the VBA project you are opening they will cause compile error in modules. Therefore, to make sure there isn’t any Excel add-in interfering with our VBA project, disable them and test opening your VBA project again.
- To do so, open the Excel application, click on the Developer tab and then click on Excel Add-ins.
- Here uncheck the excel add-ins that you think are unnecessary.
- Then, try to run the VBA code to check if the issue persists.
Solution 4. Install Correct Architecture of Microsoft Excel
If the error persists, ensure your VBA code does not contain any mistakes. If you are sure there is no mistake in your code, you can finally try installing the latest version of Microsoft Excel. If you are trying to open a file written in a 32-bit version, download the 32-bit excel version to avoid this error.