How to lock styles, remove protection, then protect doc in 2003?

K

kckc

I'm trying to lock styles only, when the doc opens (user will be able to edit
doc). Before saving, i want to remove the password protect, set all section
protectionforforms to true, then reprotect doc as well as lock styles. When
I try to set the protectionforforms, I get an error "Command not available
because document is password-protected". I ran the below macros in the order
from top to bottom for demo purposes and got the error. I have a work around
(before I set the protectionforforms, I protect the document with
Type:=wdAllowOnlyFormFields, unprotect it, set the protectionforforms, then
reprotect.) It sounds kind of silly, so I'm asking if there's a better way.

Public Sub Lock_Styles_Only()
ActiveDocument.Protect Type:=wdNoProtection, _
noreset:=False, Password:="pass", enforcestylelock:=True
End Sub

Public Sub Remove_Protection()
ActiveDocument.unprotect ("pass")
End Sub

Public Sub Protect_Doc_and_Lock_Styles()
Dim sec As Section
For Each sec In ActiveDocument.Sections
sec.ProtectedForForms = True 'error occurs here
Next sec
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
noreset:=False, Password:="lawp", enforcestylelock:=True
End Sub
 
K

kckc

please assume that all the passwords below are the same. I forgot to change
them all on this demo.
 

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