Fix Excel 2010 Run-Time Error 5 When Loading a UserForm
Question details
The user needs to identify why an Auto_Open macro produces 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.
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.
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.
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.
Choose Debug > Compile VBAProject and correct any reported syntax errors, such as a missing End If. Compile again until no further errors are reported.
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.
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.

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.

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.




