Consulting

Results 1 to 3 of 3

Thread: How can I restrict/lock parts of a word document for read only using vba

  1. #1
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location

    How can I restrict/lock parts of a word document for read only using vba

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,339
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location
    Wow, absolute genius!

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

    Thank you Greg

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •