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"
"MM" wrote: > 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".
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. MM wrote: > 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"