Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Protect for Forms (Word XP)

    Greetings.
    I'm hoping I don't have a RTFM question, but here goes: I would like to be able to protect a document as if for forms, the real reason being that want to keep authors from modifying the document in any way except to edit text. (This isn't foolproof, I know, but it would work for our needs.)
    I discovered that, for any document of more than one section, I can just loop through each section object and set ProtectedForForms to False. (This let's them type in each section, but not to change headers/footers or page setup, which is what we need.) But if the document has only one section, that command doesn't seem to work. Even if I specify ActiveDocument.Sections(1).ProtectedForForms = False, it doesn't "take." Is there something I'm missing? Also, I'd welcome any challenge to the approach I'm trying to take. (Protecting for forms seems to be the most obvious solution, but I'm open to others.)
    Thanks in advance for any input. (And pardon any syntax errors in the pseudo-code I wrote; I was doing it from memory.)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Protect for Forms (Word XP)

    In a quick test on a document with one section, it works OK if I
    1) protect the document for forms.
    2) unprotect the first (and only) section using the code you mention.
    If I omit step 1, I can still edit headers and footers, etc.

  3. #3
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Protect for Forms (Word XP)

    Oops... did I mention that I was trying to set a password when protecting the document? The actual line of code I wanted to use to protect was ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="AllenLudden"
    Apparently, the Password:= argument is the proverbial last straw.

    I kludged the following piece of code as a workaround. It's sort of inelegant... sort of like the ProtectedForForms property.

    <font face="Georgia">Sub ProtectDocumentFormat()
    Dim pSection As Section
    Dim eod As Range
    Dim SingleSectionDoc As Boolean

    'Unprotect each section first
    If MsgBox("This command will lock the document so that the user can only make text changes. Continue?", vbYesNo + vbExclamation, "Protect Document") = vbNo Then GoTo Done

    SingleSectionDoc = False

    If ActiveDocument.Sections.Count = 1 Then
    SingleSectionDoc = True
    Set eod = ActiveDocument.StoryRanges(wdMainTextStory)
    eod.Move wdStory
    eod.InsertBreak wdSectionBreakContinuous
    End If
    For Each pSection In ActiveDocument.Sections
    pSection.ProtectedForForms = False
    Next

    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Password:="AllenLudden", NoReset:=True, Type:=wdAllowOnlyFormFields
    End If

    If SingleSectionDoc = True Then eod.Delete wdCharacter, -1

    Done:
    End Sub</font face=georgia>
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Protect for Forms (Word XP)

    You should always try to provide all relevant information when asking a question. The password indeed makes the difference.

Posting Permissions

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