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
Graham Mayor - 30 May 2008 06:07 GMT
The following should reprotect sections 1 and 3 of a form (if avaiable) no
matter how many sections are present or where the cursor is at the time.
Sub ReprotectDocument()
Dim i As Long
With ActiveDocument
If .ProtectionType = wdNoProtection Then
For i = 1 To .Sections.Count
If i = 1 Or i = 3 Then
.Sections(i).ProtectedForForms = True
Else
.Sections(i).ProtectedForForms = False
End If
Next i
.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:="Mypassword"
End If
End With
End Sub

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> 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
[quoted text clipped - 28 lines]
>
> End Sub