Search notes:

Programmatic access to Visual Basic Project is not trusted

Apparently, in order to use the object model of the Visual Basic Editor, access needs to be granted.
Otherwise, a run-time error 1004 (Programmatic access to Visual Basic Project is not trusted) is thronw.

Granting access

There seem to be two possibilities to grant access to the VBA object model: via the registry and via the trust center.

Trust Center

Granting access in the Trust Center:

Via registry

Access can be granted by setting the value AccessVBOM to 1 under the respective key under an Office's Security key, for example HKCU\Software\Microsoft\Office\x.y\Excel\Security

PowerShell Module MS-Office

My PowerShell module MS-Office has the function grant-msOfficeVBAAccess which sets the AccessVBOM value in the registry.

Misc

The German translation of Programmatic access to Visual Basic Project is «Der programatische Zugriff auf das Visual Basic-Projekt ist nicht sicher».

Index