Tanya K
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Cross-posted, so I hadn't seen your prior comment
ASKER
Many thanks, Tanya