PDA

View Full Version : Solved: Protect all odd-numbered sections in Doc?



clhare
08-23-2007, 05:53 AM
I have a Word template that contains 179 sections. Once the macro is finished processing, I need to protect all the odd-numbered sections. Is there are way to do this in the macro?

Thanks!

fumei
08-23-2007, 11:22 AM
Each Section has an Index number. So determine if it is odd, or even. If it is odd, set the protection for it as true. Then protect the document. As the default is to have ALL sections checked (for protection), you must be sure to explicitly set the section protection (true or false, checked or unchecked) BEFORE you make the document protected. Like this:Sub OddSectionPorotect()
Dim oSection As Section
For Each oSection In ActiveDocument.Sections()
If oSection.Index Mod 2 <> 0 Then
oSection.ProtectedForForms = True
Else
oSection.ProtectedForForms = False
End If
Next
ActiveDocument.Protect Password:="", _
NoReset:=False, Type:= wdAllowOnlyFormFields
End Sub

clhare
08-27-2007, 08:01 AM
This works great! Thanks so much!