Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Run time error 5887
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 |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Run time error 5887
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 -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Lenny wrote: 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run time Error | Microsoft Word Help | |||
run-time error 53 | New Users | |||
run-time error | Microsoft Word Help | |||
Run-time error 91 | Microsoft Word Help | |||
Run-time error '13' | Microsoft Word Help |