Programmatic Access To Visual Basic Project Is Not Trusted

久未见 提交于 2019-11-27 04:35:10

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

This is usually needed if you are referencing Extensibility library.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!