vba 对 Visual Basic 项目的编程访问不受信任
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/25638344/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatic Access To Visual Basic Project Is Not Trusted
提问by mHelpMe
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.
我的电脑上有两个计划任务。它们都打开 Excel 文件并运行宏,并且它们的功能非常相似。他们都在我的电脑上工作。但是我将计划任务移到了同事的计算机上。一个工作另一个没有。
The one that didn't work opened Excel but had an error saying:
那个不起作用的人打开了 Excel 但有一个错误说:
"programmatic access to visual basic project is not trusted".
“对visual basic项目的编程访问不受信任”。
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,
就像我说的,两个 Excel 文件都非常相似。一个不起作用的项目确实引用了另外两个项目,而另一个则没有。他们是,
Microsoft Visual Basic for Applications Extensibility 5.3
Microsoft Windows Common Controls-2.6.0 (SP6)
I have never come across this error before.
我以前从未遇到过这个错误。
回答by
File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model.
文件 -> 选项 -> 信任中心 -> 信任中心设置 -> 宏设置 -> 对 VBA 项目对象模型的信任访问。




This is usually needed if you are referencing Extensibility library.
如果您正在引用可扩展性库,通常需要这样做。
回答by alpha_989
Its very easy to do this in Python using the pywin32module by Mark Hammond.
使用pywin32Mark Hammond的模块在 Python 中很容易做到这一点。
What the above post by @user2140173 does actually is to change some registry values. This can be programmatically accomplished by the pywin32module as follows:
@user2140173 的上述帖子实际上是更改一些注册表值。这可以通过pywin32模块以编程方式完成,如下所示:
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:
参考:
回答by Lord Anubis
Mac Version - In the past there was no setting for this on the Mac version. You did get always a dialog saying the thing.
Mac 版本 - 过去在 Mac 版本上没有设置。你确实总是得到一个说这件事的对话。
But now, at least with version 16.30, not sure how long ago, the Mac Users have the same setting available.
但是现在,至少在 16.30 版本中,不确定多久以前,Mac 用户可以使用相同的设置。
BTW, it is under security, not under trust.
顺便说一句,它是在安全之下,而不是在信任之下。
HTH
HTH

