protecting a document

M

MM

hello all,

I am trying to create a button by recording a macro to protect my
document by limiting formatting option. Here is the code when the
macro is recorded. But when I try to run the macro I get errors, here
is the code. Can someone tell me how to fix this? thank you.

Sub ProtectFormatting()

ActiveDocument.protect Password:="anything", NoReset:=False,
Type:=7, _
UseIRM:=False, EnforceStyleLock:=True

End Sub

The error is: "Parameter value is out of acceptable range"
 
J

Jean-Guy Marcil

MM said:
hello all,

I am trying to create a button by recording a macro to protect my
document by limiting formatting option. Here is the code when the
macro is recorded. But when I try to run the macro I get errors, here
is the code. Can someone tell me how to fix this? thank you.

Sub ProtectFormatting()

ActiveDocument.protect Password:="anything", NoReset:=False,
Type:=7, _
UseIRM:=False, EnforceStyleLock:=True

End Sub

The error is: "Parameter value is out of acceptable range"

The values for "Type:=" range from -1 "WdNoProtection" to 3
"wdAllowOnlyReading".
I guess, from your description, that you need "-1".
 
T

Tony Strazzeri

I find it helpful to use the defined constants whenever I can. They
are more readable and mean you don't have to remember values. You can
look up the constants in the help but they can be automatically listed
for you after you type the ":=" following the parameter name. If
you have "Auto List Members" turned on in the VBA IDE.

If you don't have this turned on already you can do so by ticking/
checking the "Auto List Members" checkbox in the "Tools| Options"
"Editor" tab in the VBA IDE.

The valid protection types are;

WdProtectionType can be one of these WdProtectionType constants.
wdAllowOnlyComments
wdAllowOnlyFormFields
wdAllowOnlyRevisions
wdNoProtection


Hope this helps.

Cheers
TonyS.
 

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