ReProtect = Reset Forms

E

Eric

Help, I'm using the following code to re-protect form fields in Odd Numbered
Sections. It works great except it is also resetting the form fields. Here
is the code that I am useing. Thanks for your help.

Sub reprotect()
Dim sPassword As String

For Each oSection In ActiveDocument.Sections
'If the section's index / 2 <> 0 (odd) protection needed'
If oSection.Index Mod 2 <> 0 Then
oSection.ProtectedForForms = True
Else
'no protection needed(even)'
oSection.ProtectedForForms = False
End If
Next
If lProtected <> wdNoProtection Then
sPassword = ""

ActiveDocument.Protect Type:=lProtected, NoReset:=True, Password:=""
End If
End Sub
 
D

Doug Robbins - Word MVP

I am not sure what

If lProtected <> wdNoProtection Then
sPassword = ""

ActiveDocument.Protect Type:=lProtected, NoReset:=True, Password:=""

but you should probably use:

With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect wdAllowOnlyFormFields, NoReset
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

The macro looks as though it has been cobbled together from some other macro
with some parts left out - see Doug's reply.

I posted code to do this a few days ago in response to a similar question,
but you appear to have ignored it. The code I posted merely applies
protection in the manner requested to an unprotected document - which is
what you asked for.

The following includes a slight addition to toggle the protection on and
off, protecting only the odd numbered sections, and the fields are not reset
in the process.

Dim i As Long
Dim Count As Integer
Dim sPassword As String
sPassword = ""
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:=sPassword
Else
Count = .Sections.Count
For i = 1 To Count
If i Mod 2 <> 0 Then
.Sections(i).ProtectedForForms = True
Else
.Sections(i).ProtectedForForms = False
End If
Next
.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=sPassword
End If
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
E

Eric

Thats perfect, thanks Graham. Previous was not ignored just got away from
me. I'm still trying to learn...

Thank you both!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top