VBA Runtime Error 361 occurs when the Visual Basic for Applications environment attempts to load or unload a UserForm or a specific object that is currently locked, corrupted, or in a conflicting state. The fastest way to resolve this is usually to restart the application to clear the memory buffer or to delete and recreate the problematic UserForm to remove internal corruption.
What You'll Need
- A computer with Microsoft Office installed (Excel, Word, or Access).
- The workbook or document containing the VBA project.
- Administrative privileges to restart the application or access system folders if necessary.
Step-by-Step
- Restart the Application
Often, this error is a transient memory glitch where the object is "stuck" in a semi-loaded state. Save your work, close the application (e.g., Excel), and ensure all processes are ended via the Task Manager if the app hangs. Relaunch the file and try to run the macro again.
- Check for Modal Conflict
If you are trying to unload a form while another modal window is open or while a specific event (like
UserForm_Initialize) is still executing, Error 361 can trigger. Review your code forUnload Mecommands. Ensure you aren't attempting to unload a form from within its own initialization event or from a conflicting event loop. - Export and Re-import the UserForm
If the error persists, the form's binary definition may be corrupted. Since you cannot always "unload" a corrupted form to fix it, you must replace it:
- Open the VBA Editor (Alt + F11).
- Right-click the problematic UserForm in the Project Explorer.
- Select Export File... and save the
.frmand.frxfiles to your desktop. - Right-click the UserForm again and select Remove [FormName]....
- When asked if you want to export the form before removing it, select No (since you already exported it).
- Right-click the project folder, select Import File..., and select the
.frmfile you saved.
- Compile the VBA Project
Syntax errors or broken references can sometimes manifest as runtime object errors. In the VBA Editor, go to the Debug menu and select Compile VBAProject. Fix any highlighted errors and save the project.
- Check for Missing References
If the object relies on an external library (like a Calendar control or a specific ActiveX component) that is missing on the current machine, the object will fail to load. Go to Tools > References and look for any items marked as "MISSING:". Uncheck the missing reference or install the required library.
Common Mistakes
- Using Unload Me in Initialize: Attempting to close a form before it has finished loading into memory is a primary cause of this error.
- Recursive Calls: Creating a loop where one form opens another, which then tries to unload the first, can create a deadlock in the object handler.
- Ignoring the Compile Button: Many users try to fix runtime errors by changing logic without first compiling the project, leaving hidden syntax errors that confuse the VBA engine.
- Over-reliance on ActiveX: Using outdated ActiveX controls (like the MSComCtl common controls) often leads to load/unload errors when moving files between different versions of Office.
Tips
- Use .Hide instead of Unload: If you need to temporarily remove a form from view but keep its data intact, use
UserForm1.Hide. This avoids the overhead of unloading and reloading the object from memory. - Naming Conventions: Ensure your UserForms and the variables used to call them have distinct names to avoid namespace conflicts.
- Binary Clean-up: If a workbook becomes "bloated" and throws frequent object errors, save the file as an
.xlsx(which strips all macros), then save it back as an.xlsmafter manually re-importing the code. This clears the hidden binary "junk" that can corrupt forms.
Troubleshooting
If the steps above do not resolve the issue, try these advanced checks:
- Test in a New Workbook: Create a brand new workbook and import only the problematic form. If it works there, the issue is with the original workbook's global state or corrupted metadata.
- Check for Third-Party Add-ins: Some COM add-ins interfere with how VBA handles memory. Disable all add-ins (File > Options > Add-ins > Go...) and restart the application to see if the error disappears.
- Update Office: Ensure you are on the latest build of Microsoft Office. Object loading bugs are occasionally patched in monthly quality updates.
- Check Bit-version Compatibility: If the project was created in 32-bit Office and is being run in 64-bit Office, certain objects (especially API declarations or ActiveX controls) will fail to load. You may need to update
Declarestatements toDeclare PtrSafe.
Frequently Asked Questions
Why does this happen suddenly in a file that worked before?
This usually occurs after an Office update, a change in the operating system's security settings, or because the binary structure of the UserForm became corrupted during a crash.
Can I fix this without deleting the form?
You can try the Compile VBAProject and Restart methods first. However, if the binary definition of the object is corrupted, exporting and re-importing is the only reliable fix.
Is this error related to my computer's RAM?
Generally, no. This is a logical or structural error within the VBA environment's object handler, not a lack of physical system memory.
Will exporting the form delete my code?
No. Exporting creates a backup file of both the visual layout and the associated code. As long as you export before removing the form, your work is safe.
Does this happen more often with ActiveX controls?
Yes. ActiveX controls are external dependencies. If the version of the control on your system differs from the version used to create the form, VBA may fail to load the object.