PDA

View Full Version : [SOLVED:] How can I restrict/lock parts of a word document for read only using vba



Artair
11-13-2016, 08:22 AM
Hello,


I have a word document (a form) that contains two sections. I need to protect the first section of the form for No changes (Read only), whilst keeping the second section restricted to 'Filling in forms'.

I only seem to be able to do one or the other; or I can restrict editing (for Filling in Forms) to one section and leave the other section completely unprotected, but this is not what I want. So far I have not been able to find any suggestion this is even possible, so I am hoping someone either knows how I can achieve this or can be offer a different approach?

My goal is that I have a form in Word that starts off as protected for forms. When section 1 has been completed, a button is pressed which locks that section against any further alterations (read only), leaving section 2 as protected for forms so it can be completed by someone else.

The fields in the form are legacy Text Form Fields and Checkboxes (rather than the content controls found in Word 2003 and above - this is out of necessity). I have considered the approach of setting the enabled property of the formfields in section 1 to False, but this also stops a user from selecting the text so they may copy it, and I would like to avoid this if I can.

If anyone can advise how I can get different protection types on different section of the document, or has any other suggestions on how I can prevent a section of a document from being edited, I would be most grateful. I am using Word 2003.

Thank you

gmaxey
11-13-2016, 05:01 PM
As far as I know, you can't do that. This might work:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oFld As FormField
ActiveDocument.Unprotect
ActiveDocument.Protect wdAllowOnlyReading
For Each oFld In ActiveDocument.Sections(2).Range.FormFields
oFld.Range.Editors.Add wdEditorEveryone
Next
lbl_Exit:
Exit Sub

End Sub

Artair
11-14-2016, 11:20 AM
Wow, absolute genius!

That's perfect and does exactly what I was after.

Thank you Greg