Changing Security Settings with VBA

L

Lloyd

We are trying to install customized letterhead templates
that have VBA code in them, and which require a code
module to be added to the Normal template.
Unfortunately, to do this via code requires temporarily
resetting the security settings to low and trusting VB
Projects.

Is there a way to use VBA code to change security
settings In Word to allow a template to be loaded by VBA
code?

Thanks for any help.

Lloyd
 
J

JGM

Hi Lloyd.

No. Otherwise any malicious programmer could write damaging code... Word is
not very secure as it is...

But I am curious... Why do you want to create a module in the Normal.dot? It
is not recommended to play around with the user's normal.dot. There must be
a better/more stable way of achieving the results you desire....No?

HTh
Cheers!
 
C

Cindy M -WordMVP-

Hi Lloyd,

In Word 2002 and later you can do this using the
Application.AutomationSecurity property.
We are trying to install customized letterhead templates
that have VBA code in them, and which require a code
module to be added to the Normal template.
Unfortunately, to do this via code requires temporarily
resetting the security settings to low and trusting VB
Projects.

Is there a way to use VBA code to change security
settings In Word to allow a template to be loaded by VBA
code?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
L

lloyd

Thanks for getting back to me. I realize the security
risks involved with changing the security settings,
however, there doesn't seem to be any other way to
achieve what I need to achieve.

I have found it useful to put code in a module inside the
normal template to allow a custom toolbar button to
automatically open a new instance of the letterhead
template I've designed. I haven't figured out any other
way to achieve this.

Thanks again,

Lloyd
 
J

JGM

Hi Cindy,

Can you please explain how you would use that property?

With Word XP, if the user's security is set to "High", then you cannot run
any code at all, so the property will not work. If the security is set to
"Medium" and the user chooses to deactivate the macros, we are back to
square one (same as "High"). OTOH, if the user chooses to activate the
macros, you do not need this property. Finally, if the security is set to
"Low", you do not need the property...
The only practical way I can see to use this property, is to deactivate code
when programmatically opening files and you do not want code that might be
in the ThisDocument_Open module to be executed.

Or I totally missed Lloyd's problem! The way I see it is that if he cannot
modify the Normal.dot VBA project because the security is set to high, then
no code at all will run... what have I missed? Must be something simple... I
always miss the "in your face" stuff! ;-)

TIA
 
L

Lloyd

Hi Cindy, thanks for responding so quickly. TIA, thanks
also for adding your thoughts. I'd like to add a couple
of further related queries to this.

I've just looked up the AutomationSecurity property in
the Help menu and tried using the example code to see how
it works. Oddly enough, resetting this property to
say "1," which presumably represents "Low" in the Tools |
Macros | Security | Security Level tab, doesn't actually
change the setting in this security tab dialog box. Nor
does it change the "Trust all add-ins and templates"
and "Trust access to Visual Basic Project" check boxes.
I'm therefore wondering what is actually being changed by
this property that is not covered by the Security
Settings dialogue box?

My second confusion is that the help topic on this
property mentions that it is automatically set to
msoAutomationSecurityLow when Word is started. By
contrast I've always found that the setting in the
Security level tab is always set to "High" by default.

My third confusion is: How do you in fact change
the "Trust all add-ins and templates" and "Trust access
to Visual Basic Project" settings programmatically? I
especially need to be able to change the "Trust access to
Visual Basic Project" programmatically in order to auto
install the new templates.

TIA's query: If I understand TIA's confusion correctly,
it sounds like a variant of mine. Boiled down, what
relationship does the property have to the Security
settings in the Tools | Macros | Security | Security
Level tab?

Thanks a lot for your time and assistance with this.
It's a huge help for us here at my institution.

Lloyd
 
J

JGM

Heu Lloyd...

"TIA" stands for "Thanks In Advance"...

I think that you should look up how to use Global templates (Templates in
the Word start up folder) to add the functionality you are talking about...
So you would need your letterhead template and a template just to add the
custom toolbar to call the letterhead.

HTH ("Hope That Helps"!)
Cheers!
--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

"Lloyd" <[email protected]> a écrit dans le message de
[email protected]...
Hi Cindy, thanks for responding so quickly. TIA, thanks
also for adding your thoughts. I'd like to add a couple
of further related queries to this.

I've just looked up the AutomationSecurity property in
the Help menu and tried using the example code to see how
it works. Oddly enough, resetting this property to
say "1," which presumably represents "Low" in the Tools |
Macros | Security | Security Level tab, doesn't actually
change the setting in this security tab dialog box. Nor
does it change the "Trust all add-ins and templates"
and "Trust access to Visual Basic Project" check boxes.
I'm therefore wondering what is actually being changed by
this property that is not covered by the Security
Settings dialogue box?

My second confusion is that the help topic on this
property mentions that it is automatically set to
msoAutomationSecurityLow when Word is started. By
contrast I've always found that the setting in the
Security level tab is always set to "High" by default.

My third confusion is: How do you in fact change
the "Trust all add-ins and templates" and "Trust access
to Visual Basic Project" settings programmatically? I
especially need to be able to change the "Trust access to
Visual Basic Project" programmatically in order to auto
install the new templates.

TIA's query: If I understand TIA's confusion correctly,
it sounds like a variant of mine. Boiled down, what
relationship does the property have to the Security
settings in the Tools | Macros | Security | Security
Level tab?

Thanks a lot for your time and assistance with this.
It's a huge help for us here at my institution.

Lloyd
 
T

Thomas Winter

Cindy, I don't mean to butt in here, but it looks like the
AutomationSecurity property is meant to work like the old DisableAutoMacros
command in WordBasic. It appears this setting only affects things that
macros do, that is things that are done with Automation. (Automation is sort
of a fancy word for macros.) It doesn't appear to relate to the security
settings dialog box, which affects what the USER does. (Opening files, etc.)

If you would use an add-in (especially a signed add-in) you would avoid all
(or most) of these security problems.

-Tom
 
L

Lloyd

Thanks to all for your input. I believe the add-in
approach suggested by Tom and others is the approach that
I've been looking for. It appears to by pass the issues
I've been dealing with.

Thanks again, to all.

lloyd
 
S

Shifty

I don't know exactly what type of office network you operate in, but
couldn't you create a digital signature and then have everyone trust
that source? This would mean you wouldn't have to monkey around with
individual security settings.

You can also create personal ones, but they only work on your system.
 
C

Charles Kenyon

1) There's no reason to be changing normal.dot to install customized
letterhead templates. Use a different global.

2) You can set security to trust vba in Add-Ins and in the templates folder.
The Add-In (the different global template) goes in the Word Startup folder.

3) Yes, once the security is already allowing you to run your project, your
project can change the security settings. If the security is set to not
allow your project to run, it can't change the security settings. Otherwise
the security settings would be just so much Microsoft PR.
--

Charles Kenyon

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Cindy M -WordMVP-

Hi Lloyd (and all)

The way I interpreted the original question was that you
already had code that was successfully working with/in Word.
In that case AutomationSecurity will do the job just fine
for opening documents that themselves contain code. Of
course, if you're talking about getting started at all, then
AutomationSecurity is not useful. In that case you'd need an
Addin (as suggested by others), or possibly a digital
signature.
My third confusion is: How do you in fact change
the "Trust all add-ins and templates" and "Trust access
to Visual Basic Project" settings programmatically? I
especially need to be able to change the "Trust access to
Visual Basic Project" programmatically in order to auto
install the new templates.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top