Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

ms access - How to get rid of VBA security warning

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 = "SoftwareMicrosoftOffice12.0AccessSecurityTrusted LocationsYourTrustedLocationName"
        .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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...