Programmatically set "Trust Access To Visual Basic Project" to on, then off (Tools > Macros > Security > Trusted Publishers tab)

Hi.  I'd like to keep my users from having to set this Macro security setting in order to use my template with buttons.  Also, I don't think it is a good idea to leave it checked.  What is the code to change the setting to on when the document is opened, then to change to off when the document is closed?  I can't find the setting in the Word VB objects browser.  If it can't be done, fine, I'll just make the users do it as part of "setting up the tool"... but I have some real doozy users and it would be nice to do this automatically for them.

Thanks!

e
epugliseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Hi e,

This can't be done via code, for an obvious reason: this setting is there for security reasons, and that security would
be worthless if malicious code could disable it :)

Well, maybe it can be done with some arcane Registry tweaking using APIs.  IMHO, you're better off not going there...

Regards,

Patrick
GrahamSkanRetiredCommented:
It would not be logical to allow the code to set access to itself so, no, it can't be done by design.
mgalig1010Commented:
I'm not sure about this but would creating a certificate and signing the word template help? The users would have to trust your certificate. Once they did that, opening templates signed by you would be seemless.

Just something to look into, I haven't actually done this.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Patrick MatthewsCommented:
mgalig,

This is a different issue.  The "trust access to the VB project" setting controls whether or not to
allow programmatic access to the VBProject itself or its dependent objects.  For example, if this
access is allowed, you can write code that actually edits code elsewhere in the project, among
other things.

For example, I have code that imports BAS files as new modules into the ActiveWorkbook's VBProject;
that code only works if programmatic access is allowed.

Patrick
mgalig1010Commented:
Thanks for the info Patrcik!
R_RajeshCommented:
try this:

Set wsh = CreateObject("WScript.Shell")
'key to modify
str1 = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\" & _
Application.Version & "\Word\Security\AccessVBOM"
'enable access
wsh.RegWrite str1, 1, "REG_DWORD"
'read the vba project name
MsgBox Application.NormalTemplate.VBProject.Name
'disable access
wsh.RegDelete str1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Patrick MatthewsCommented:
Rajesh,

I knew it was possible; I typically tell people to stay *FAR* away from manipulating the Registry :)

BTW, how would one test to see the current setting, so that the change would only be needed if the
user is currently not allowing access to the VBProject?

Patrick
R_RajeshCommented:
using on error resume next statement and testing for error...
Patrick MatthewsCommented:
Duh!

How silly of me :)

Thanks,

Patrick
epugliseAuthor Commented:
R_Rajesh:  I can't wait to try this out.  I'll give it a whirl and see...

Patrick MatthewsCommented:
Yoana,

The answer should go to Rajesh.

Regards,

Patrick
epugliseAuthor Commented:
Sorry, I didn't realize I hadn't assigned points here.  My apologies to Rajesh.
R_RajeshCommented:
No harm done, epuglise. Thanks for the Grade!
And Patrick, thanks for the assist :)
Patrick MatthewsCommented:
You're most welcome, Rajesh.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.