How to get rid of VBA security warning
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 wh开发者_高级运维o 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.
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:
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)
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.
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.
Have your macro signed by a trusted authority.
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.
When everything is ok and the install is complete, MS Access (at default configuration) now trusts the database.
Good Luck ;)
Grtz, Tom
精彩评论