vba 如何摆脱VBA安全警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3195580/
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
How to get rid of VBA security warning
提问by masfenix
I developed a Access application using VBA. Everytime I open Access up, I get the following:
我使用 VBA 开发了一个 Access 应用程序。每次打开 Access 时,都会得到以下信息:


I have to click Options-> Enable Contentto run my macros. This application will be shared among a couple of people at work who are not so tech savvy. So as per requirements, I must remove it. I've tried signing/packaging the database, but it still does not get rid of the warning.
我必须单击“选项”->“启用内容”才能运行我的宏。此应用程序将在工作中不太精通技术的几个人之间共享。因此,根据要求,我必须将其删除。我试过对数据库进行签名/打包,但它仍然没有消除警告。
回答by Trefex
To do that you have to add the location from where the Excel is launched in the "Trusted Locations".
为此,您必须在“受信任的位置”中添加启动 Excel 的位置。
To do this, do as follows:
为此,请执行以下操作:
- In Excel Options, go to Trust Center and then Trusted Locations
- Add the location.
- 在 Excel 选项中,转到信任中心,然后转到受信任的位置
- 添加位置。
This would have to be done on a per-pc basis.
这必须在每台电脑的基础上完成。
In addition, there is no way to do this from an Excel file point of view as this would completely anihiliate the security feature of letting the user chose to run VBA code or not.
此外,从 Excel 文件的角度来看,没有办法做到这一点,因为这将完全消除让用户选择是否运行 VBA 代码的安全功能。
Also a little sidenote, if you sign your Excel file, you'd still need the recipient to trust you as a publisher, so that's why your solution probably did not work.
还有一点旁注,如果您签署 Excel 文件,您仍然需要收件人信任您作为发布者,所以这就是您的解决方案可能不起作用的原因。
Edit:
编辑:
Taking into comments, there does seem to be a way to do it programmatically. As taken from XpertsExchange,
考虑到评论,似乎确实有一种以编程方式进行的方法。取自 XpertsExchange,
Why not just set the registry entry from code, without invoking Shell? Use the cRegistry class found here:
为什么不直接从代码设置注册表项,而不调用 Shell?使用此处找到的 cRegistry 类:
VBA Code:
VBA 代码:
Dim c As New cRegistry
With c
.ClassKey = HKEY_CURRENT_USER
.SectionKey = "Software\Microsoft\Office.0\Access\Security\Trusted Locations\YourTrustedLocationName"
.ValueKey = "Path"
.ValueType = REG_DWORD
.Value = "Full path to Trusted Folder"
End With
The only caveat is that YourTrustedLocationname must be unique ...
唯一的警告是 YourTrustedLocationname 必须是唯一的......
You'd have to try if it should be .ValueType = REG_DWORD or REG_SZ. I'm not sure on that one.
您必须尝试它是否应该是 .ValueType = REG_DWORD 或 REG_SZ。我不确定那个。
回答by Juan Manuel Perez
Though this question is years old, just in case it may help, here is what I did. It is a different approach to those already proposed, and it may serve someone else. In my case, MsAccess was not opened directly by the user. Instead, MsAccess was started using automation from within another custom application. So, instead of having the user to click ‘Enable Content', we had this custom application tell MsAccess to enable the macros. Something similar to this:
虽然这个问题已经存在多年了,但以防万一它可能有所帮助,这就是我所做的。这是一种与已经提出的方法不同的方法,它可能会为其他人服务。就我而言,MsAccess 不是由用户直接打开的。相反,MsAccess 是从另一个自定义应用程序中使用自动化启动的。因此,我们没有让用户单击“启用内容”,而是让这个自定义应用程序告诉 MsAccess 启用宏。类似的东西:
cli = create_object("Access.Application")
cli.AutomationSecurity = 1 # 1 = msoAutomationSecurityLow
cli.visible = true
cli.opencurrentdatabase("c:/Users/jmperez/AppData/Local/Temp/DB_TMP.mdb")
(sorry about the above code, it's not from a ‘standard' or ‘popular' programming language, but it shouldn't be difficult to adapt to Visual Basic or anything else)
(抱歉上面的代码,它不是来自“标准”或“流行”的编程语言,但适应 Visual Basic 或其他任何东西应该不难)
回答by Fosco
It's a per-user option. Everyone would need to 'trust' your workbook.
这是每个用户的选项。每个人都需要“信任”你的工作簿。
In Excel, hit the menu button, and choose Excel Options. In that window, pick Trust Center, and then Trust Center Settings. In that window, choose Trusted Locations.
在 Excel 中,点击菜单按钮,然后选择 Excel 选项。在该窗口中,选择信任中心,然后选择信任中心设置。在该窗口中,选择受信任的位置。
Once on that screen, you will probably want to check "Allow Trusted Locations on my network" and then click Add Location and add the network location of your workbook.
在该屏幕上,您可能需要选中“允许我的网络上的受信任位置”,然后单击“添加位置”并添加工作簿的网络位置。
回答by mcandre
Have your macro signed by a trusted authority.
让您的宏由受信任的机构签名。
回答by Tom
What I did was creating a setup project with visual studio 2010 (under setup & deployment projects). Within this project you configure to install/copy the MS Access application to "C:\Ntapps\MsOffice\Office12\ACCWIZ\". This is a folder for trusted databases. Then create a shortcut to the MS Access application and install that one at the desired location.
我所做的是使用 Visual Studio 2010 创建一个安装项目(在安装和部署项目下)。在此项目中,您配置将 MS Access 应用程序安装/复制到“C:\Ntapps\MsOffice\Office12\ACCWIZ\”。这是受信任数据库的文件夹。然后创建 MS Access 应用程序的快捷方式,并将其安装在所需位置。
When everything is ok and the install is complete, MS Access (at default configuration) now trusts the database.
当一切正常并且安装完成后,MS Access(在默认配置下)现在信任该数据库。
Good Luck ;)
祝你好运 ;)
Grtz, Tom
格茨,汤姆

