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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…