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.
- File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model.
- 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