在本文中,我们将讨论如何修复 Excel 中的 VBA 错误 400 的(how to fix VBA error 400 in Excel)方法。Excel中的错误 400通常在运行Microsoft Visual Basic for Applications ( VBA ) 宏时发生。它会导致宏崩溃或无法运行并返回错误 400 消息。现在,这种错误可能有不同的原因;让我们讨论一下。
![vba-error-400-in-excel](https://1.bp.blogspot.com/-CyIyg3PBTVI/YVAtU2BKlJI/AAAAAAAAGHk/yNSU07Z5nPsJAabFUdQ1yI7v11_yCoSNgCLcBGAsYHQ/s0/0f3cpUCcY85Q_lWp0-ya0wUZTzE.png)
什么导致 Excel 中的 VBA 错误 400?
以下是在Excel中运行(Excel)宏(Macro)时触发错误 400 的原因:
- (Faulty)Office软件安装错误。
- VBA代码中有一些错误。
- 参数中的值无效。
- 正在运行的宏已损坏。
- 受某些恶意软件感染的 Excel 相关文件。
- 无法从文件读取/写入。
- 无效的注册表项。
如果您在Excel中遇到错误 400 ,您可以使用下面列出的解决方案来解决它。
如何修复 Excel 中的 VBA 错误 400
以下是修复在Excel(Excel)中运行宏时遇到的错误 400 的方法:
- 将宏移动到新模块。
- 启用对 VBA 的可信访问。
- 查看您的 VBA 代码。
- 修复 Microsoft Excel。
- 卸载,然后重新安装Excel。
- 其他一些方法,例如扫描恶意软件等。
让我们详细讨论这些方法。
1]将宏移动到新模块
如果出现一些外部错误,将宏转移到新模块可能会解决问题。您可以使用以下步骤来执行此操作:
转到“开发人员( Developers)”选项卡,然后单击“可视化( Visual) 编辑器”(editor)选项。如果您在Excel(Excel)的主功能区上看不到Developers选项卡,请转到File >Options并从Customize Ribbons选项卡,打开Main Tabs部分的Developers复选框。
![](https://1.bp.blogspot.com/-cG9ytF1QgyM/YVJxTvRBAyI/AAAAAAAAIjg/DydYjLy8u1sPpGZmiZq6Ix95JpkZsxVwgCLcBGAsYHQ/s0/GBcryOSxIJO1aK-sVhuJ8V-qKIg.png)
现在,在Microsoft Visual Basic for Applications窗口中,单击插入(Insert)菜单,然后单击模块(Module)选项。
![](https://1.bp.blogspot.com/-WnhRfgsj-WY/YVXBkhxfGfI/AAAAAAAAQQ0/gmoxlr8LBj4aXr_9elBdhCpIRo3OedhYACLcBGAsYHQ/s0/z9w3A6_Vux-RthLurZ04Dbjx0n8.png)
之后,将您的宏(Macro)代码粘贴到这个新模块中,并使用“文件(File)”菜单中的专用选项保存它。
此外,您需要通过右键单击旧模块并使用“删除(Remove)”选项来删除它。
最后,点击File > Close and Return to Microsoft Excel选项,看看错误 400 是否在Excel中得到解决。
2]启用对VBA的可信访问
![](https://1.bp.blogspot.com/-EcuQMDVtkqA/YVAzUy3jkXI/AAAAAAAAGzU/Ax96nWSbW1IgGWfqLJXtKLDdCeh6PNVjQCLcBGAsYHQ/s0/3jeyUEJ-DfiObHhrfWwDJnuCan4.png)
您可以打开对VBA的受信任访问,看看问题是否消失了。以下是启用对VBA(VBA)的可信访问的步骤:
- 移动到开发人员(Developers)选项卡,然后单击宏安全(Macros Security)选项。
- 在Trust Center(Trust Centre)窗口中,启用名为Trusted access to the VBA project object model的选项。
- 按确定按钮。
3]检查您的代码
VBA代码中的错误可能会在Excel中触发错误 400 。因此,您需要彻底检查宏代码并更正代码中的错误(如果有)。此外,如果有任何损坏,请检查宏。
4]修复Microsoft Excel
![](https://1.bp.blogspot.com/-0BqJWNJqDpM/YVU4dax_lUI/AAAAAAAALpc/A2XYDwXFqT8QYWjtud3uZFY-5iVrBfzxwCPcBGAYYCw/s0/SZUelceSHvO2G-BqimvsHBynopk.png)
如果上述方法均无效,则问题可能出在Excel应用程序上。该应用程序可能安装不正确或需要修复。因此,请使用以下步骤修复Microsoft Excel :
- 启动设置应用程序(Launch Settings app)并转到应用程序 > 应用程序和功能。
- 在右侧,找到并单击Office 365/ Microsoft 365程序。
- 点击修改(Modify)按钮,然后选择在线修复(Online Repair)或快速修复(Quick Repair)选项。
- 按修复(Press)Excel和其他Office应用程序的修复(Repair)按钮。
5]卸载(Uninstall),然后重新安装Excel
您也可以尝试卸载然后重新安装 Office和Excel软件以重新开始。看看这是否修复了错误。
6]其他一些方法
此外,其他一些解决方案也可能像这样工作:
- 您可以尝试运行 SFC 扫描来检查和修复损坏的系统文件。
- 一些恶意程序也可能导致此错误。因此,请使用Microsoft Defender或第三方防病毒(antivirus)或反恶意软件(antimalware)程序检查并删除恶意软件和可疑应用程序。
- 尝试删除损坏的缓存数据和系统垃圾文件。
希望以上解决方案有所帮助!
现在阅读:(Now read: )如何修复 Excel 中的运行时错误 1004(How to Fix Runtime Error 1004 in Excel)
How to fix VBA error 400 in Excel
In this article, we are going to discuss methods on how to fix VBA error 400 in Excel. The error 400 in Excel usually occurs while running a Microsoft Visual Basic for Applications (VBA) macro. It causes the macros to crash or fail to run and return an error 400 message. Now, there can be different reasons for such an error; let us discuss them.
![vba-error-400-in-excel](https://1.bp.blogspot.com/-CyIyg3PBTVI/YVAtU2BKlJI/AAAAAAAAGHk/yNSU07Z5nPsJAabFUdQ1yI7v11_yCoSNgCLcBGAsYHQ/s0/0f3cpUCcY85Q_lWp0-ya0wUZTzE.png)
What causes VBA error 400 in Excel?
Here are the reasons due to which error 400 is triggered when running a Macro in Excel:
- Faulty installation of the Office software.
- There is some error in the VBA code.
- Invalid value in the argument.
- The running macro is corrupted.
- Excel-related files infected by some malware.
- Failure to read/ write from a file.
- Invalid registry entries.
If you are encountering error 400 in Excel, you can use the below-listed solutions to resolve it.
How to fix VBA error 400 in Excel
Here are the methods to fix error 400 encountered while running a macro in Excel:
- Move Macros to a new Module.
- Enable trusted access to VBA.
- Review your VBA code.
- Repair Microsoft Excel.
- Uninstall, and then reinstall Excel.
- Some other methods like scan for malware, etc.
Let us discuss these methods elaborately.
1] Move Macros to a new Module
Transferring your macros to a new module may fix the issue in case there is some external error. You can use the below steps to do so:
Go to the Developers tab and click on the Visual editor option. In case you don’t see the Developers tab on the main ribbon in Excel, go to File > Options and from Customize Ribbons tab, turn on the Developers checkbox from the Main Tabs section.
![](https://1.bp.blogspot.com/-cG9ytF1QgyM/YVJxTvRBAyI/AAAAAAAAIjg/DydYjLy8u1sPpGZmiZq6Ix95JpkZsxVwgCLcBGAsYHQ/s0/GBcryOSxIJO1aK-sVhuJ8V-qKIg.png)
Now, in the Microsoft Visual Basic for Applications window, click on the Insert menu and then the Module option.
![](https://1.bp.blogspot.com/-WnhRfgsj-WY/YVXBkhxfGfI/AAAAAAAAQQ0/gmoxlr8LBj4aXr_9elBdhCpIRo3OedhYACLcBGAsYHQ/s0/z9w3A6_Vux-RthLurZ04Dbjx0n8.png)
After that, paste your Macro code into this new module and save it using the dedicated option from the File menu.
Also, you need to delete the old module by right-clicking it and using the Remove option.
At last, click the File > Close and Return to Microsoft Excel option and see if the error 400 is resolved in Excel.
2] Enable trusted access to VBA
![](https://1.bp.blogspot.com/-EcuQMDVtkqA/YVAzUy3jkXI/AAAAAAAAGzU/Ax96nWSbW1IgGWfqLJXtKLDdCeh6PNVjQCLcBGAsYHQ/s0/3jeyUEJ-DfiObHhrfWwDJnuCan4.png)
You can turn on the trusted access to VBA and see if the issue is gone. Here are the steps to enable trusted access to VBA:
- Move to the Developers tab and click on the Macros Security option.
- In the Trust Centre window, enable the option named Trusted access to the VBA project object model.
- Press the OK button.
3] Review your code
An error in VBA code can trigger error 400 in Excel. So, you need to thoroughly review the macro code and correct the error in the code if any. Also, check macros if there is any corruption.
4] Repair Microsoft Excel
![](https://1.bp.blogspot.com/-0BqJWNJqDpM/YVU4dax_lUI/AAAAAAAALpc/A2XYDwXFqT8QYWjtud3uZFY-5iVrBfzxwCPcBGAYYCw/s0/SZUelceSHvO2G-BqimvsHBynopk.png)
If none of the above works, the problem might be with the Excel app. The application might be installed incorrectly or something needs to be repaired. So, repair Microsoft Excel using the below steps:
- Launch Settings app and go to Apps > Apps & features.
- On the right, locate and click Office 365/ Microsoft 365 program.
- Tap on the Modify button and then select Online Repair or Quick Repair option.
- Press the Repair button which repairs Excel and other Office apps.
5] Uninstall, and then reinstall Excel
You can also try to uninstall and then reinstall Office and Excel software to start afresh. See if this fixes up the error.
6] Some Other Methods
Also, some other solutions may also work like:
- You can try running an SFC scan to check and repair corrupted system files.
- Some malicious programs can also cause this error. So, check and remove malware and suspicious application with Microsoft Defender or third-party antivirus or antimalware program.
- Try deleting corrupted cache data and system junk files.
Hope the above solutions help!
Now read: How to Fix Runtime Error 1004 in Excel