Forms - Protecting Sections

P

Paul Brown

Hello all,

I have created a Word 97 form which is basically in 2 parts. The first
section contains numerous fixed fields and drop down boxes and this section
is protected. The second section is an area for freeformat text and so is
unprotected. Within the form I have a Macro which when activated copies
sections 1 and 2 and creates sections 3 and 4 the first time, 5 and 6 the
second time, etc. After the Macro has run I need to reprotect all odd
numbered sections and leave all even numbered sections available for
freeformat text. Is there any way to do this?

ActiveDocument.Sections(all odd numbered sections).ProtectedForForms = True
ActiveDocument.Sections(all even numbered sections).ProtectedForForms =
False
ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields

Grateful for any assistance.

Paul.

PS low level knowledge of VBA - use the recorder to perform the bulk of the
action and then edit a bit where necessary.
 
J

Jay Freedman

Paul said:
Hello all,

I have created a Word 97 form which is basically in 2 parts. The first
section contains numerous fixed fields and drop down boxes and this
section is protected. The second section is an area for freeformat
text and so is unprotected. Within the form I have a Macro which when
activated copies sections 1 and 2 and creates sections 3 and 4 the
first time, 5 and 6 the second time, etc. After the Macro has run I
need to reprotect all odd numbered sections and leave all even
numbered sections available for freeformat text. Is there any way to
do this?

ActiveDocument.Sections(all odd numbered sections).ProtectedForForms
= True
ActiveDocument.Sections(all even numbered
sections).ProtectedForForms = False
ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields

Grateful for any assistance.

Paul.

PS low level knowledge of VBA - use the recorder to perform the bulk
of the action and then edit a bit where necessary.

Hi Paul,

I'd do it this way (explanation follows code):

Dim nThisSec As Integer
With ActiveDocument
For nThisSec = 1 To .Sections.Count
If nThisSec Mod 2 = 1 Then ' odd
.Sections(nThisSec).ProtectedForForms = True
Else ' even
.Sections(nThisSec).ProtectedForForms = False
End If
Next nThisSec

.Protect Password:="", NoReset:=True, _
Type:=wdAllowOnlyFormFields
End With

The With ActiveDocument statement (paired with the End With statement) means
that each variable that begins with a dot should be understood to have
"ActiveDocument" before the dot.

The For statement (paired with the Next statement) creates a loop that
starts by assigning nThisSec = 1, and increases its value by 1 each time
around the loop until the value reaches the number of sections in the
document. That is, the loop goes around once for each section.

The If statement (together with the Else and End If statements) determines
what happens in each circuit through the loop. The expression "nThisSec Mod
2" means "divide the value of nThisSec by 2, and give me the remainder". If
the value of nThisSec for this loop circuit is odd, the remainder will be
1, so ProtectedForForms will be set to True. If the value of nThisSec is
even, then the remainder will be 0; the statement after the Else line will
be executed and ProtectedForForms will be set to False.

After all the sections have been processed, the .Protect statement will turn
on the protection in the odd-numbered sections.
 
P

Paul Brown

Paul said:
Hi Paul,

I'd do it this way (explanation follows code):

Dim nThisSec As Integer
With ActiveDocument
For nThisSec = 1 To .Sections.Count
If nThisSec Mod 2 = 1 Then ' odd
.Sections(nThisSec).ProtectedForForms = True
Else ' even
.Sections(nThisSec).ProtectedForForms = False
End If
Next nThisSec

.Protect Password:="", NoReset:=True, _
Type:=wdAllowOnlyFormFields
End With

The With ActiveDocument statement (paired with the End With statement)
means
that each variable that begins with a dot should be understood to have
"ActiveDocument" before the dot.

The For statement (paired with the Next statement) creates a loop that
starts by assigning nThisSec = 1, and increases its value by 1 each time
around the loop until the value reaches the number of sections in the
document. That is, the loop goes around once for each section.

The If statement (together with the Else and End If statements) determines
what happens in each circuit through the loop. The expression "nThisSec
Mod
2" means "divide the value of nThisSec by 2, and give me the remainder".
If
the value of nThisSec for this loop circuit is odd, the remainder will be
1, so ProtectedForForms will be set to True. If the value of nThisSec is
even, then the remainder will be 0; the statement after the Else line will
be executed and ProtectedForForms will be set to False.

After all the sections have been processed, the .Protect statement will
turn
on the protection in the odd-numbered sections.
Hi Jay,

Many thanks - works like a dream.

Paul.
 

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