[VBA] Fix “Unknown Runtime Error” When Executing VBScript Files: Check Security Settings

目次

Background

When I tried to execute an external VBScript file (.vbs) from VBA, I encountered an error message saying “Unknown runtime error,” and the script would not run.

At first, I thought there was a mistake in my script code. However, after investigating, I found that the cause was Excel’s security settings.

This article summarizes the cause and the specific steps to resolve this issue.

Cause: Excel Macro Security Restrictions

The main cause of the error is that Excel’s security settings are blocking VBA from calling external scripts (VBScript). This setting is disabled by default and must be explicitly enabled.

Solution: Enable “Trust access to the VBA project object model”

Please change the Excel security settings using the following steps.

Steps:

  1. Open Excel.
  2. Click the File tab.
  3. Select Options at the bottom left.
  4. Select Trust Center.
  5. Click the Trust Center Settings… button.
  6. Select Macro Settings.
  7. Check the box for Trust access to the VBA project object model.
  8. Click OK to close all windows, then restart Excel.

Supplement: Why is this setting necessary?

This setting controls whether VBA is allowed to access other VBA projects or external scripts. On corporate PCs or shared devices, this is often disabled by default to prevent risks from viruses or malicious scripts.

Caution

  • Changing security settings carries the risk of allowing unintended scripts to run. Only enable this in a trusted environment.
  • This error can occur not only with .vbs files but also with processes using the Shell function or the WScript.Shell object.

Summary

If you see “Unknown runtime error” and cannot execute a VBScript file, reviewing Excel’s security settings is the most effective solution.

Specifically, verify the following setting:

  • Check “Trust access to the VBA project object model”

When using processes that link macros with external scripts, it is important to prepare the security environment in advance.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次