The error "Excel VBA module not found" typically happens because the specific code module is missing from the workbook, the workbook is saved as a macro-free format, or the VBA editor is looking at the wrong project. To fix this, open the VBA editor, check the Project Explorer for the missing module, insert a new standard module if necessary, and ensure the workbook is saved in the proper macro-enabled format (.xlsm). If the module exists but is invisible, uncheck the "Project Properties" to reveal it.

What You'll Need

  • A computer running Microsoft Windows with Microsoft Excel installed (Excel 2010 or later is recommended).
  • The Excel file containing the code that is throwing the error.
  • Basic familiarity with the keyboard (Alt + F11 to open the editor) and mouse navigation.

Step-by-Step

  1. Open the VBA Editor. Launch your Microsoft Excel application. Press the keyboard shortcut Alt + F11 simultaneously to open the Visual Basic for Applications (VBA) editor window. This is the dedicated space for writing and managing your code.
  2. Locate the Project Explorer. Look for a window labeled Project Explorer on the left side of the VBA editor. If this window is not visible, go to the top menu bar, click on View, and select Project Explorer from the dropdown list. This window lists all open workbooks and their constituent components, such as sheets and modules.
  3. Verify the Workbook Name. Ensure you are looking at the correct project in the Project Explorer. Click on the small plus sign (+) next to the file name to expand the tree structure. You should see folders labeled Forms, Modules, Class Modules, and Microsoft Excel Objects.
  4. Check for the Missing Module. Look inside the Modules folder. If the module you are looking for is missing, you will see an empty folder or a folder with no items listed. This confirms the error—the code that the spreadsheet is trying to run is simply not there.
  5. Insert a New Standard Module. If the module is truly missing, you must recreate it. Right-click on the Modules folder in your specific project. Hover over Insert in the context menu and select Module. A new, empty window will appear on the right side of the editor.
  6. Copy and Paste the Code. Open a backup file or a source document where you know the correct VBA code is located. Select the code, copy it (Ctrl + C), and paste it into the new module window you just created (Ctrl + V). Ensure the code is syntactically correct; if there are syntax errors, the line will turn red, and you will need to fix those before the code will run.
  7. Check for Hidden Modules. Sometimes a module exists but is hidden from view. In the Project Explorer, right-click on the specific project name at the very top of the tree (not the folder, but the file name itself). Select Properties from the menu. In the Project Properties dialog box that appears, click on the Protect tab. Look for an option labeled Lock project for viewing. If this is checked, the module is locked and cannot be edited or viewed.
  8. Reveal the Module. To reveal a hidden module, you must uncheck the Lock project for viewing box. You will be prompted to enter a password. If you do not know the password, you cannot unlock the project using this method. If you do know the password, enter it and click OK. You can then expand the Modules folder to find the code.
  9. Save the File as Macro-Enabled. This is a critical step that often causes the error. If the file is saved as a standard Excel Workbook (.xlsx), all VBA code is stripped out when the file is closed. To save your work, go to the top menu in Excel and click File > Save As. In the Save as type dropdown menu, select Excel Macro-Enabled Workbook (*.xlsm). Name your file and click Save.
  10. Close and Reopen. Close the Excel application completely. Relaunch Excel and open the .xlsm file you just saved. Press Alt + F11 again to verify that the module is now present and visible in the Project Explorer.
  11. Update References (If Applicable). If the error persists even though the module is present, the issue may be a missing external reference. In the VBA editor, go to Tools > References. A list of available references will appear. If any reference is marked as MISSING, uncheck it. Sometimes, updating the reference to the correct version of the library (e.g., Microsoft Scripting Runtime) resolves the issue.

Common Mistakes

One of the most frequent mistakes is saving the file in the wrong format. Users often save a file with VBA code as a standard .xlsx file, which strips out the code and leaves the macro references broken. Another common error is assuming the code is in the file when it is actually in a template or an add-in that is not currently attached. Additionally, users often forget that code is case-sensitive, so a function call like GetData() will fail if the actual function is named getdata().

Tips

To keep your VBA code organized, always name your modules descriptively, such as "Module_DataProcessing" or "Module_ErrorHandling". This makes it much easier to find the correct module later. When debugging, use the Immediate Window (Ctrl + G) to print values and test lines of code step-by-step. This is faster than setting breakpoints and allows you to see exactly what the computer is reading at any given moment.

Troubleshooting

If you have followed the steps above and the module is still not found, try copying all the code from the new module and pasting it into a completely new, blank workbook. This tests whether the issue is with the specific file or with a corrupted project. If the code runs fine in the new workbook, the original file is likely corrupted, and you will need to copy your data (sheets and values) into a fresh workbook and re-enter the VBA code.

Frequently Asked Questions

Why does Excel say "Module not found"?

This error occurs when the spreadsheet attempts to run a function, subroutine, or procedure that exists in a specific module, but that module has been deleted, not inserted, or the file was saved without macros.

How do I know if my Excel file has macros?

You can check by looking at the file extension. Files with the .xlsm extension contain macros and are the correct format for VBA code. Files with .xlsx do not support macros.

Can I recover a deleted module?

If you have not saved the file, you can sometimes recover the code by opening the file immediately and pressing Ctrl + Z in the VBA editor. If you have saved the file, the code is likely gone unless you have a backup copy.

Why is the module folder empty?

An empty Modules folder simply means no standard modules have been inserted into that specific workbook project. You can insert a new module by right-clicking the folder and selecting Insert > Module.

Do macros work in Excel Online?

No, Excel Online does not support VBA macros. Macros can only be used in the desktop versions of Excel for Windows and Mac.