30 Advanced Excel Tips for 2026

Excel Champs / VBA / VBA Error 400 (How to Fix it)
By Puneet Gogia (Microsoft MVP)

VBA Error 400 (How to Fix it)

Error 400 in VBA means “Form already displayed; can’t show modal”: the code calls UserForm1.Show for a form that’s already on screen. Check whether it’s visible before showing it:

If Not UserForm1.Visible Then UserForm1.Show

Excel also shows a plain message box reading only “400” when some macros run from a button or the Macros dialog fail, without saying what went wrong. To find the real error, open the Visual Basic Editor (Alt + F11), click inside the macro and press F8 to step through it; the line that fails shows the actual error number and message.

If the code runs cleanly when you step through it but still shows 400 from the button, copy the code into a new module (Insert → Module) and delete the old one. That clears a damaged module, a fix that often works for the bare 400 box.

Add an error handler, On Error GoTo with MsgBox Err.Number & ": " & Err.Description after the label, so the next failure names the real error instead of showing 400.

What is Error 400 in VBA

Error 400 in VBA is like a message “something’s not right” that pops up when your Excel macro runs into a problem. It doesn’t give you specific details about what went wrong, so it can be tricky to figure out. This error often happens if there’s an issue with how the macro interacts with Excel, like trying to do something that isn’t allowed or possible at the moment.

It is a run-time error that is not so common, but there are a few situations where you could face this error. This error occurs when something fails while Excel is running a macro, and VBA can’t show a proper error message for it.

And different reasons can make it fail:

  • If your macro tries to access a range or a cell incorrectly (e.g., referencing a non-existent range), this might trigger the error. Check your range references and ensure they are valid.
  • If you recently installed new add-ins, they might conflict with your macro.
  • Changing UserForms inappropriately (like unloading them incorrectly) might cause this error. Review how UserForms are managed in your code.
  • A corrupted global template in Excel can also lead to Error 400.
  • A faulty installation of Microsoft Excel.
  • Excel failed to read from or write to a file, or tried to access an object that does not exist or has been moved.
  • The macro that you are trying to execute is corrupt.
  • Or there could be a virus or malware on the system.

It appears as a simple message box displaying “400” with no further details.

Microsoft also documents one specific Error 400: “Form already displayed; can’t show modally”. You get it when you use the Show method to open a UserForm as a modal form while that form is already visible. I have covered the fix for this one below.

How to Fix VBA Error 400

It is a little tricky to fix error 400, as it doesn’t come with any message about what is causing it. But you can use a few ways to fix it.

Debug the Code and Execute Each Line of Code One by One

Debugging code by executing each line one at a time is a great way to understand how your code works and find where errors occur.

  • Step Into (F8): This button lets you execute your code line by line. When a line calls a subroutine or function, stepping in will take you into that subroutine or function.
  • Step Over (Shift + F8): This executes the next line of code but doesn’t enter any called procedures. Instead, it runs them in the background and moves to the next line in the procedure.
  • Step Out (Ctrl + Shift + F8): If you are inside a subroutine or function, this will run the rest of it and pause once it returns to the calling procedure.

To start, open the VBA editor (Alt + F11), click anywhere inside the macro and press F8. Keep pressing F8 until the 400 message appears. The last line that was highlighted is the one that causes the error.

Apart from that, there could be a possibility of having a virus or malware that can cause this error. So, you can also use an antivirus to scan your system and all the files that you are trying to access with the macro.

Run the Macro from the VBA Editor

When you run a macro from a button or the Macros dialog box, you may only see “400”. Run the same macro from the VBA editor by pressing F5 instead. Very often, you then get the real error message with a Debug button that takes you to the line with the problem.

Also, go to Debug ➜ Compile VBAProject. It checks all the code in the file and points to any line that has a syntax error or an undeclared variable.

Show the Real Error with Error Handling

Add an error handler to the macro so it shows the error number and description instead of just “400”:

Sub myMacro()
On Error GoTo ErrorHandler
' your code here
Range("A1").Value = 100
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
End Sub

Fix “Form Already Displayed; Can’t Show Modally”

If the error comes from a UserForm, hide or unload the form before you show it again as a modal form. Or check if it’s already visible before you show it:

Sub ShowMyForm()
If Not UserForm1.Visible Then
UserForm1.Show vbModal
End If
End Sub

Move the Code to a New Module

Sometimes the module itself gets corrupted. In that case, insert a new module (Insert ➜ Module), copy the code into it, and delete the old module (right-click it ➜ Remove, and click Yes to export a copy first). After that, save the file and run the macro again.

Check Add-ins and Repair Office

  1. First of all, start Excel in safe mode by holding the Ctrl key while you open it. Safe mode doesn’t load add-ins, so if the macro works there, an add-in is the cause.
  2. After that, go to File ➜ Options ➜ Add-ins, and turn off the add-ins one by one to find the one that conflicts with your macro.
  3. In the end, if nothing works, repair Office from the Control Panel (Programs and Features ➜ Microsoft Office ➜ Change), starting with Quick Repair and then Online Repair.

Frequently Asked Questions

Why does Error 400 show only “400” with no message?

This usually happens when the macro is started from a button or the Macros dialog box and VBA can’t show the normal run-time error window. Run the macro from the VBA editor with F5 or F8, or add an error handler, to see the actual error.

Does Error 400 mean my file is corrupted?

Not always. Most of the time, it’s a problem in the code, like a wrong range reference. Check the code first, and only then try moving the code to a new module or repairing Office.

Can I use On Error Resume Next to hide Error 400?

You can, but it only hides the problem, and the line that failed won’t do its job. It’s better to find the line with F8 and fix it.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel
Author Photo

My name is Puneet and I am the founder of ExcelChamps.com. I have been awarded Microsoft MVP for Excel for my contribution to the Excel Community through this blog, YouTube Channel, and LinkedIn.