Programmatic Access To Visual Basic Project Is Not Trusted
Asked Answered
H

3

64

I have two scheduled tasks on my computer. They both open Excel files and run a macro & are pretty similar in what they do. They both work on my computer. However I moved the scheduled tasks onto a colleague's computer. One worked the other didn't.

The one that didn't work opened Excel but had an error saying:

"programmatic access to visual basic project is not trusted".

Like I say, both Excel files are very similar. The one that didn't work does reference two additional projects the other one does not. They are,

Microsoft Visual Basic for Applications Extensibility 5.3
Microsoft Windows Common Controls-2.6.0 (SP6)

I have never come across this error before.

Haemato answered 3/9, 2014 at 7:11 Comment(0)
S
121

File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model.

enter image description here

enter image description here

This is usually needed if you are referencing Extensibility library.

Sura answered 3/9, 2014 at 7:15 Comment(3)
+ 1 Also closed the question to be moved to superuser :)Precincts
How do you do this programmatically?Solberg
Be warned, this is something that System Administrators can lock with Group Policy.Sunfish
A
6

Its very easy to do this in Python using the pywin32 module by Mark Hammond.

What the above post by @user2140173 does actually is to change some registry values. This can be programmatically accomplished by the pywin32 module as follows:

import win32api
import win32con

key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,
                            "Software\\Microsoft\\Office\\16.0\\Excel"
                            + "\\Security", 0, win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(key, "AccessVBOM", 0, win32con.REG_DWORD, 1)

Ref:

  1. http://docs.activestate.com/activepython/2.4/pywin32/win32api__RegSetValueEx_meth.html
  2. http://docs.activestate.com/activepython/2.4/pywin32/win32api__RegOpenKeyEx_meth.html
Academe answered 3/8, 2018 at 19:45 Comment(2)
im so glad someone could show me the reg path so I could deploy en-masse! Thank you. Set-ItemProperty -path HKCU:\Software\Microsoft\Office\16.0\Excel\security -Name "AccessVBOM" -Value 1Stolen
See https://mcmap.net/q/245154/-programatically-bringing-up-excel-39-s-quot-trust-center-settings-quot-dialog for a method to do this from VBAEmployer
D
4

Mac Version - In the past there was no setting for this on the Mac version. You did get always a dialog saying the thing.

But now, at least with version 16.30, not sure how long ago, the Mac Users have the same setting available.

BTW, it is under security, not under trust.

HTH

screenshot privacy trust VBA object model

Deach answered 20/10, 2019 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.