How to write a macro to protect fields within word

Hello.  I have created a form in word 2010 with four sections, each section to be completed by a seperate operator.  
Each section of the form has a combination of rich text content control fields, date pickers, and drop down lists.  
I would like to create a macro, assigned to a button under each section, such that once section one has been completed, the operator clicks the button and all the fields within section one are locked/protected from further editing.  The next macro assigned to a second button, would protect all the fields within section two.
I am aware that you can restrict editing, however the above is to make it easier for operators.
All and any assistance would be greatly appreciated.  
Thank you
Tanya
Tanya KAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
This should do it for Section 1:
Sub ProtectFields()
    Dim sec As Section
    Dim cc As ContentControl
    
    Set sec = ActiveDocument.Sections(1)
    For Each cc In sec.Range.ContentControls
        cc.LockContents = True
    Next cc
End Sub

Open in new window

0
 
Tanya KAuthor Commented:
Graham, thank you very much for your extremely prompt reply!  I have been able to apply your above code to my form for all my sections and it has worked perfectly.  I have been trying for the last couple of days to resolve this issue, and so I really appreciate your expertise.
 Many thanks, Tanya
0
 
GrahamSkanRetiredCommented:
Better, to reduce the amount of code,  you can use one procedure. Place the  each MacroButton field within the section and find the Section from the Selection.

Sub ProtectFields()
    Dim sec As Section
    Dim cc As ContentControl
    
    Set sec = Selection.Sections(1)
    For Each cc In sec.Range.ContentControls
        cc.LockContents = True
    Next cc
End Sub

Open in new window

0
 
GrahamSkanRetiredCommented:
Cross-posted, so I hadn't seen your prior comment
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.