What Is “Compile Error in Hidden Module” in Excel VBA?
A “Compile Error in Hidden Module” is a security alert in Excel VBA. It usually occurs when the VBA code is incompatible with the version or architecture of the Excel application. When you attempt to run the code, this alert pops up.
Reason 1 – Password-Protected VBA Module
If you have a password-protected VBA module, it will act as a hidden module. To resolve this, you need full access to the Excel file containing the module. Otherwise, you’ll require permission from the file’s owner.
Solution – Unprotect the VBA Module
Follow these steps to fix the error:
- Enable the Developer tab:
- Go to the File menu.
-
- Select Options in the Overview Panel.
-
- Choose the Customize Ribbon tab.
- Check the Developer feature under Customize the Ribbon.
- Click OK to close the Excel Options box.
- Navigate to the Developer tab and select Visual Basic under the Code section.
- Right-click on the hidden module and choose VBAProject Properties.
- In the VBAProject – Project Properties window, go to the Protection tab and remove the password.
- Press OK.
- Your code should now run successfully in Excel.
Read More: VBA Object Variable or with Block Variable Not Set in Excel
Reason 2 – Missing References in Visual Basic Editor (VBE)
When working with Objects from different applications in Excel VBA, you need to add references to the object libraries of those applications. If specific references are unavailable, it can result in a “Compile Error in Hidden Module”.
Solution – Activate Missing References in VBE
To resolve this issue:
- Open the Developer tab and click on Visual Basic in your workbook.
- Select References from the Tools menu.
- Scroll through the list of Available References.
- Mark the Microsoft Word 16.0 Object Library reference (or any other relevant reference) to enable it.
- Press OK to close the window.
- Try running the VBA code again, and the error should no longer appear.
Read More: [Fixed!] Subscript Out of Range Error in Excel VBA
Reason 3 – MS Excel Containing Template Files of Add-ins
Third-party Excel Add-ins, such as Adobe Acrobat PDF Maker, can enhance Excel’s functionality. However, if these add-ins are incompatible with the VBA project, they can cause a compile error in hidden modules.
Solution – Remove External Add-ins
You can address this issue from both the Excel Developer tab and the Excel Start-up Folder:
- Remove Add-ins from Developer Tab:
- Open Excel Add-ins from the Developer tab.
-
- Uncheck any add-ins that you don’t need.
- Press OK.
2. Remove Add-ins from Excel Start-up Folder
Follow the steps below to remove any unnecessary add-ins from the Excel Start-up Folder.
- Close all open Excel files.
- Navigate to the XLSTART folder (usually located in C:\Users\USERNAME\AppData\Roaming\Microsoft\Excel).
- Delete any unused XLA or XLAM files.
- Restart Excel, and the error should be fixed.
Read More: Reasons And Solutions for Excel Object Required Error in VBA
Reason 4 – Incorrect Syntax in VBA Code
If the previous solutions didn’t resolve the issue, there might be incorrect syntax in the VBA code.
Solution – Fix Syntax Errors in VBA Code
Follow these steps:
- Press Alt + F11 to open the Visual Basic Editor.
- Click on Compile VBAProject under the Debug tab while your code is open.
- If there’s a syntax error, it will be highlighted.
- Press OK and correct the code where indicated.
- Open Debug again, and if the Compile VBAProject option is grayed out, the code has been successfully compiled, and the error is resolved.
Read More: [Fixed!] Excel Application-Defined or Object-Defined Error in VBA
Reason 5 – Unsupported Registered OCX Files
OCX files are Windows ActiveX Control files used for customizing and reusing user interface design. Unregistered or incompatible OCX files can lead to a “Compile Error in Hidden Module in Excel”.
Solution – Re-register OCX Files Using Command Prompt (CMD)
To solve this issue:
- Press the Windows key + R to open the Run box.
- Enter cmd and press OK.
- Depending on your system version insert one of the following commands in the Command Prompt (cmd):
- For 32-bit systems:
regsvr32 -u c:\windows\system32\mscomctl.ocx
regsvr32 c:\windows\system32\mscomctl.ocx
- For 64-bit systems:
regsvr32 -u c:\windows\syswow64\mscomctl.ocx
regsvr32 c:\windows\syswow64\mscomctl.ocx
Run Excel, and the Compile Error in Hidden Module should no longer occur.
Read More: [Fixed!] Invalid Forward Reference in VBA
Reason 6 – Unwanted .exd Files in Device Folders
.exd files stored in device folders allow faster access to additional controls. However, misalignment with the application can cause a compile error.
Solution – Delete .exd Files
- Open the Run dialog.
- Enter %appdata% and press OK.
- Navigate to the Application Data Folder.
- Open the Microsoft folder.
- Inside the Forms folder, select the files and delete them.
- Restart Excel, and the error will be resolved.
Read More: [Fixed!] Unable to Set the Visible Property of the Worksheet Class
How to Externally Solve “Compile Error in Hidden Module” for Excel
If the previously provided solutions don’t completely resolve the issue, you can try the following external methods to fix the “Compile Error in Hidden Module “in Excel.
Method 1 – Move Adobe Acrobat PDF Maker Files
If you have installed Adobe Acrobat PDF Maker on your device, then you need to relocate the pdfmaker.dot file and pdfmaker.xla files to a different location. Follow these steps:
- Click the Windows icon and enter * in the search bar.
- Select the files and folders that appear.
- In the All or part of the file name field enter * and search for it.
- Locate the dot & pdfmaker.xla files in the folder > right-click > choose the Cut option.
- Paste them to a location of your choice on your Desktop to resolve the error.
Read More: Because of Your Security Settings Macros Have Been Disabled
Method 2 – Update Available Latest Version of Adobe Acrobat
Ensure that your installed Adobe Acrobat software is up to date:
- Open Adobe Acrobat.
- Click on Help in Adobe’s window.
- Choose Check for Updates to open the updater window.
- If any updates are available, press Download and Install.
Method 3 – Uninstall Norton Antivirus Software
To address the error, consider uninstalling Norton Antivirus Software from your device instead of updating it:
- Press Windows + R to open the Run dialog.
- Enter cpl in Run dialog and click OK.
- From the list, select the Norton Antivirus software.
- Click the Uninstall button to remove the software after confirmation.
Read More: [Fixed!] Method Open of Object Workbooks Failed
Frequently Asked Questions
1. How can I open Excel in safe mode?
To open Excel in safe mode, press and hold the Ctrl button while opening the file. You can also apply the safe switch (e.g., excel.exe /safe) when starting the program from the command line.
2. How can I repair MS Excel when it crashes?
Microsoft has introduced the MS Excel Repair Tool, available in all Excel versions. This tool quickly fixes crashes, sorts damaged or corrupted Excel files, and recovers erased or lost data from spreadsheets, cell comments, pivot charts, functions, and formulas.
Related Articles:
- [Solved]: User Defined Type Not Defined in Excel VBA
- Sub or Function Not Defined in Excel VBA
- [Solved!] Excel VBA “Argument Not Optional” Error