How to Fix Excel VBA Runtime Error 400?

Microsoft Excel application is one of the most used programs for organizational tasks. It has various features and functionalities to efficiently manage and organize data, create tables, and charts, and build different formulas and relations between data. One such feature of Excel is that it enables users to create VBA (Visual Basic for Application) macros [an action or set of actions in Excel that enables users to run as many times as they want]. Sometimes, while running macros users encounter ‘VBA Error 400’ that fails or crashes the Microsoft Excel program.

Excel

What is VBA Runtime Error 400?

Excel uses VBA codes to automate repetitive actions. But, sometimes while running the VBA codes users may experience the ‘error 400’. It generally occurs when there is an issue with the code like you have entered the code in the wrong module or at times when Excel fails to read the queries due to corruption within the Excel file. When the VBA runtime error 400 occurs, it disrupts the macro execution and interrupts your workflow.

What Causes VBA Runtime Error 400?

There are various reasons that cause the VBA runtime error 400. Following are some of the reasons:

  • Registry entries are invalid.
  • Problem with the module in which you are running the macro.
  • Corrupt macros.
  • Incorrect parameter or argument in macros.
  • Virus-infected download or incomplete installation of Microsoft Excel program.
  • Corruption in important Excel-related files.
  • Outdated version of Excel program.
  • Trying to get access to an object that does not exist.

Methods to Fix Excel VBA Runtime Error 400

There are various solutions, methods, and workaround to fix the VBA runtime error 400. Following are a few methods that can resolve the runtime error 400:

Method 1: Move the Macro to Another Module

If there are problems in a module, you may encounter the VBA runtime error 400 in Excel. For instance, when you insert a code in the wrong module in the VBA project and get an error, then there is an issue with the module. If this happens, you can fix it by moving your macros to another module. Following are the steps to do so:

Launch the Microsoft Excel application.

First, create a new module using the following steps:

image1

  • In Excel, go to the extreme right for the Developer tab, and click.

  • Now, select ‘Visual Basic’ to open the Microsoft Visual Basic Applications wizard.

  • In the VBA, click on ‘Insert’, and then select ‘Module’.
  • Copy the code from the previous (old) module and paste it into the new module you created.

  • Now, click on ‘File’, and then to save the code in the new module, click ‘Save’.
  • Open the old module, right-click on it, and then click on ‘Remove’ to delete the old module.

You may check if the error is fixed or not by running the code.

Method 2: Enable Trusted Access to VBA

If the above method does not rectify the VBA runtime error 400, then you can enable the trusted access to the VBA option in the Excel application to give complete access to the code to run.

The following are the steps:

  • Select the ‘Developer’ tab on the Excel menu, and then click on ‘Macro Security’.

  • In the ‘Trust Centre’ window, under ‘Developer Macro Settings’ select the ‘Trust access to the VBA project object model’.

  • To save the changes, click OK.

Method 3: Enable All Macros Settings

Incorrect Macro settings can stop you from executing macros, which may result in errors like the VBA runtime error 400. To fix the error, you can check and enable the Macro settings using the following steps:

  • Go to the affected Excel file.

  • Now, click on the ‘Developer’ tab, and then click on ‘Macro Security’.

  • In the ‘Trust Center’ window, under ‘Macro Settings’ click on the radio button in front of ‘Enable all macros’.
  • Click ‘OK’ to apply the changes.

Method 4: Check the VBA Code

Excel VBA runtime error 400 can also occur when an object you want to work within a code is unavailable, deleted, or inaccessible. You can check and correct the code using the VBA editor. It requires you to use the debug command.

Following are the steps to check and debug to identify and fix the errors in VBA code:

  • Open Excel, click on the ‘Developer’ tab and then click the Visual Basic option.

  • In the Visual Basic editor, look on the tabs above, find ‘Debug’ and select, and then click Compile from the options.
  • If there is any syntax error, the above action will highlight it. Check the code and make the changes required.

Method 5: Repair the Excel File

The Excel VBA runtime error 400 can also occur when your Excel file gets corrupted or damaged. If so, then you need to repair the Excel file using the built-in ‘Open and Repair’ tool in the application. You can follow the steps to repair your corrupt or damaged Excel file:

  • Open Excel and go to the ‘File’.

  • From the drop-down, click on Open, in the resulting box, select the corrupted Excel file.

  • At the bottom of the box, click on the arrow next to the Open button, and select ‘Open and Repair’ from the option.

  • When prompted, select the ‘Repair’ option.

The in-built ‘Open and Repair’ tool may not be able to repair severely corrupted Excel files or highly damaged files. If so, then you may require a better solution, like the third-party Excel repair tool ‘Stellar Repair for Excel’. A highly advanced and powerful tool uses advanced algorithms to repair a corrupted Excel file, even if it is extensively damaged. It can easily recover all the components of the Excel file, including macros, formulas, cells, tables, etc. while maintaining complete integrity.

Stellar Repair for Excel is also compatible with all the versions of the Excel application, including Excel 2019, 2016, and 2013. This tool can help you extensively in fixing all the complex Excel issues associated with Excel file corruption.

Excel error

Conclusion: 

When VBA runtime error 400 occurs, it stops macros and other query execution in the Excel file. It may occur due to numerous reasons, like invalid parameters in macros, deleted objects, or corruption in Excel files. To fix the Excel VBA runtime 400 error, you can apply the different solutions discussed above. However, sometimes the runtime error 400 can also be caused by the corruption in the Excel file, if so then you can use an advanced and powerful third-party tool like Stellar Repair for Excel to repair the affected Excel file. The software can efficiently repair corrupted macros in Excel and maintain complete integrity during the repair process. It repairs and restores all the Excel file data with integrity and 100% accuracy.