Excel Error Codes

Fix Excel 2010 Run-Time Error 5 When Loading a UserForm

Rana GarciaRana Garcia Nov 22, 2026 868 views

Question details

The user needs to identify why an Auto_Open macro produces Run-Time Error 5 when loading a UserForm.

Fix Excel 2010 Run-Time Error 5 When Loading a UserForm
Product
Microsoft Excel 2010
Device & OS
not provided
Scenario
An Auto_Open macro loads and displays a UserForm when the workbook opens.
Observed behavior
Excel reports Run-Time Error 5, Invalid procedure call or argument, although the form opens in the VBA editor.
Before you start

Open the workbook in Excel and press Alt+F11 to access the VBA editor. Enable macros only if you trust the workbook, and locate both the Auto_Open procedure and the UserForm in Project Explorer.

Solution 1Recommended

Check the UserForm name and initialization code

Use the VBA editor to find an incorrect form reference or an invalid argument executed while the form loads.

1
Check the form name

In the VBA editor, select the UserForm in Project Explorer and press F4 to open Properties. Compare its (Name) property with the name in the Auto_Open Load statement, such as Load frmDevScreenStatus.

2
Compile the project

Choose Debug > Compile VBAProject and correct any reported syntax errors, such as a missing End If. Compile again until no further errors are reported.

3
Step through the macro

Open Auto_Open, place the cursor inside the procedure, and press F8 to step through it. When execution reaches Load, continue stepping into UserForm_Initialize and check the highlighted statement for invalid arguments or values.

4
Test recent changes

In the UserForm code window, temporarily comment out recently added initialization statements, save the workbook, and test the form again. Restore the statements one at a time to identify any code that triggers the error.

Check the UserForm name and initialization code
If the error disappears: In the reported case, commenting out recent initialization code, saving, and restoring it resolved the issue. This may indicate a temporary project issue, but it does not establish corruption as the cause.
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 Excel file formats, making it easy to move everyday spreadsheet work between office suites. It does not fix Excel's VBA error; test macro and UserForm compatibility before migrating automated workbooks.

Open and edit common Excel formats, including XLS and XLSXUse a familiar spreadsheet interface for everyday workbook tasksMove spreadsheet content between office suites with easeWork in a free, lightweight Office alternative
QA img-9

Frequently Asked Questions

What does Run-Time Error 5 mean in Excel VBA?

It means a procedure received an invalid call or argument. When loading a UserForm, check the code executed during initialization, including values passed to methods and properties.

How do I find the name used in the Load statement?

Press Alt+F11, select the form in Project Explorer, and press F4. Use its (Name) property in the Load statement rather than its displayed caption.

Why does the form open in the editor but fail when the macro runs?

Opening the form designer does not necessarily execute the same initialization code as loading the form. Step through Auto_Open with F8 and inspect UserForm_Initialize.

Can a missing End If cause this error?

A missing End If is a syntax issue that can prevent the project from compiling. Choose Debug > Compile VBAProject to find and correct it, then test the form again.