Skip to main content

Programmatic access to Visual Basic Project is not trusted

Table of contents
  1. Symptoms
  2. Cause
  3. Resolution

Symptoms

When I run an Excel macro, I get an error message: Run-time error'1004: Programmatic access to Visual Basic Project is not trusted

Cause

Excel adds a security option to deliberately lock out programmatic access to the VBA object model from any Automation client unless a user chooses to permit such access. This is a per user and per application setting, and denies access by default.

This security option makes it more difficult for unauthorized programs to build "self-replicating" code that can harm end-user systems.

Resolution

For any Automation client to be able to access the VBA object model programmatically, the user running the code must explicitly grant access. To turn on access, please read Macro Security Settings, or follow these steps.

  1. File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model.
  2. To turn on access, select the check box and click OK to apply the setting.

If you want to use VBA to enable it, read this article: Excel Macro: Enable Trust Access to the VBA Project Object Model

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>