VBA & Macro Problems

Fix VBComponent and CodeModule Type Errors in Excel VBA

Khadija KhanKhadija Khan Nov 18, 2026 868 views

Question details

The user needs to resolve undefined type errors for VBComponent and CodeModule in an Excel VBA workbook.

Fix VBComponent and CodeModule Type Errors in Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In the affected workbook, open Developer > Visual Basic, or press Alt+F11 where available.

2
Open the reference list

In the VBA editor, select the workbook's project in Project Explorer, then choose Tools > References.

3
Enable the reference

Select Microsoft Visual Basic for Applications Extensibility 5.3 in the list and click OK.

4
Compile and save

Choose Debug > Compile VBAProject to check the code, then return to Excel and save the workbook.

Enable the VBA Extensibility 5.3 reference
The reference is workbook-specific: The reference is saved with the workbook. If a reference appears as MISSING after the workbook is opened in another Excel version, check Tools > References and reset it if the required library is available.
Free Microsoft Office alternative

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.

Open and edit common Microsoft Excel formats, including XLSX and XLSUse a familiar spreadsheet interface for everyday workbook tasksMove standard spreadsheet work from Excel to a lightweight office suiteWork with spreadsheet data while keeping Excel-specific VBA troubleshooting separate
microsoft office alternative - wps office

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.