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
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