L
Lenny
I have created the following code in Module 1 of a Word Form w/fill-in fields
and have created a small toolbar with Protect and Unprotect buttons which
allows the user to unlock the form to access mail merge and then re-protect
the document per company requirements.
When it re-locks with password, only sections 1 and 3 are protected, 2 and 4
+ any additional sections that may be created are un-protected. When I first
ran the code it bombed, and based on the error message, realized the curson
was in a section that was protected in the code. When I placed the cursor in
section 4 (always unprotected), it worked a couple of times then started
giving me the error message 5887 and in the vb editor, highlights this line.
ActiveDocument.Sections(1).ProtectedForForms = True
What is wrong with the code and why did it work, then not?
Regards, Lenny
Sub ReprotectDocument()
'
' Reprotect Unlocked Document
' Macro recorded 6/29/2004
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:="my password"
If ActiveDocument.Sections.Count = 4 Then _
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
End If
End Sub
and have created a small toolbar with Protect and Unprotect buttons which
allows the user to unlock the form to access mail merge and then re-protect
the document per company requirements.
When it re-locks with password, only sections 1 and 3 are protected, 2 and 4
+ any additional sections that may be created are un-protected. When I first
ran the code it bombed, and based on the error message, realized the curson
was in a section that was protected in the code. When I placed the cursor in
section 4 (always unprotected), it worked a couple of times then started
giving me the error message 5887 and in the vb editor, highlights this line.
ActiveDocument.Sections(1).ProtectedForForms = True
What is wrong with the code and why did it work, then not?
Regards, Lenny
Sub ReprotectDocument()
'
' Reprotect Unlocked Document
' Macro recorded 6/29/2004
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:="my password"
If ActiveDocument.Sections.Count = 4 Then _
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
End If
End Sub