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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
data protection

From novice to tech pro — start learning today.