Fix VBComponent and CodeModule Type Errors in Excel VBA
Question details
The user needs to resolve undefined type errors for VBComponent and CodeModule in an Excel VBA workbook.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- The workbook contains VBA code that uses VBComponent and CodeModule types.
- Observed behavior
- Excel VBA reports User-defined type not defined because the Microsoft Visual Basic for Applications Extensibility 5.3 reference is missing.
Open the affected workbook in desktop Excel and make sure you can access its VBA editor. If the workbook contains macros, save it in a macro-enabled format such as .xlsm.
Enable the VBA Extensibility 5.3 reference
Use this solution when VBComponent or CodeModule is reported as an undefined type because the workbook lacks the required reference.
In the affected workbook, open Developer > Visual Basic, or press Alt+F11 where available.
In the VBA editor, select the workbook's project in Project Explorer, then choose Tools > References.
Select Microsoft Visual Basic for Applications Extensibility 5.3 in the list and click OK.
Choose Debug > Compile VBAProject to check the code, then return to Excel and save the workbook.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work to WPS. It does not repair Excel VBA references, and VBA compatibility may vary.

Frequently Asked Questions
Why does Excel say VBComponent or CodeModule is not defined?
These types require the Microsoft Visual Basic for Applications Extensibility 5.3 reference. In the VBA editor, check Tools > References and enable it for the affected workbook.
Does the reference apply to every workbook?
No. The reference is saved with the workbook's VBA project, so enable it in each workbook that needs it.
What should I do if the reference is marked MISSING?
Open the workbook's VBA editor and choose Tools > References. Check the missing entry and reset the reference if the required library is available in that Excel installation.
Will enabling the reference allow code to modify VBA projects?
The reference resolves the type definitions, but programmatic access to the VBA project may also require the Trust access to the VBA project object model setting in Excel's Trust Center.




