如何摆脱VBA安全警告 [英] How to get rid of VBA security warning

查看:510
本文介绍了如何摆脱VBA安全警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VBA开发了Access应用程序.每次我打开Access时,都会得到以下信息:

https://lh5.googleusercontent.com/wgn5B5PllVXGuG6W4_xiFa1rouSpDSn27MC0nzPkgJ5CPN8BKpAn-gDFsVS4GZtepY-c4jtbEupKeV227ogICQlzcg=s512"

我必须单击选项-> 启用内容来运行宏.该应用程序将在不那么精通技术的工作人员中共享.因此,按照要求,我必须将其删除.我已经尝试过对数据库进行签名/打包,但是仍然无法消除警告.

解决方案

为此,您必须在受信任位置"中添加启动Excel的位置.

为此,请执行以下操作:

  • 在Excel选项中,依次转到信任中心"和受信任的位置"
  • 添加位置.

这必须以每台PC为基础.

此外,从Excel文件的角度来看,这是没有办法的,因为这将完全削弱使用户选择是否运行VBA代码的安全性功能.

还有一点便笺,如果您签署Excel文件,您仍然需要收件人来信任您作为发布者,因此这就是您的解决方案可能行不通的原因.

考虑到评论,似乎确实存在以编程方式进行评论的方法.摘自XpertsExchange,

为什么不直接从代码中设置注册表项,而不调用Shell?使用在此处找到的cRegistry类:

http://www.vbaccelerator.com/主页/VB/代码/库/Registry_and_Ini_Files/Complete_Registry_Control/article.asp

VBA代码:

 Dim c As New cRegistry
    With c
        .ClassKey = HKEY_CURRENT_USER
        .SectionKey = "Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\YourTrustedLocationName"
        .ValueKey = "Path"
        .ValueType = REG_DWORD
        .Value = "Full path to Trusted Folder"
    End With

唯一的警告是YourTrustedLocationname必须是唯一的...

您必须尝试将其设置为.ValueType = REG_DWORD或REG_SZ.我不确定那个.

I developed a Access application using VBA. Everytime I open Access up, I get the following:

I have to click Options -> Enable Content to 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.

解决方案

To do that you have to add the location from where the Excel is launched in the "Trusted Locations".

To do this, do as follows:

  • In Excel Options, go to Trust Center and then Trusted Locations
  • Add the location.

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.

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.

Edit:

Taking into comments, there does seem to be a way to do it programmatically. As taken from XpertsExchange,

Why not just set the registry entry from code, without invoking Shell? Use the cRegistry class found here:

http://www.vbaccelerator.com/home/VB/Code/Libraries/Registry_and_Ini_Files/Complete_Registry_Control/article.asp

VBA Code:

 Dim c As New cRegistry
    With c
        .ClassKey = HKEY_CURRENT_USER
        .SectionKey = "Software\Microsoft\Office\12.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 ...

You'd have to try if it should be .ValueType = REG_DWORD or REG_SZ. I'm not sure on that one.

这篇关于如何摆脱VBA安全警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆