#1   Report Post  
Posted to microsoft.public.word.docmanagement
Lenny Lenny is offline
external usenet poster
 
Posts: 74
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run time Error Le Tam Microsoft Word Help 1 March 22nd 07 11:47 AM
run-time error 53 Genia New Users 2 March 1st 07 07:07 PM
run-time error JohnnyBoy Microsoft Word Help 1 July 24th 06 06:31 AM
Run-time error 91 JMildren Microsoft Word Help 1 May 13th 05 07:47 PM
Run-time error '13' Kelli Microsoft Word Help 1 April 30th 05 01:30 AM


All times are GMT +1. The time now is 11:21 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"