Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Aug 2004
    Posts
    361
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Locking Down a Word Document (Word 2002)

    The following code will lock down an Excel workbook. I then lock out a user being able to password protect the code.

    Sub LockedBook()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    ws.Protect Password:="yankeezulu", Contents:=True

    Next
    End Sub

    Is there a similar method to do so in Word?

    Thanks.

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

    Re: Locking Down a Word Document (Word 2002)

    You can protect a document for forms using Tools | Protect Document..., or in VBA

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, Password:="Secret"

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Locking Down a Word Document (Word 2002)

    You could try
    <code>ActiveDocument.Protect Type:=wdAllowOnlyReading, NoReset:=True, Password:="XYZZY"</code>

    wdAllowOnlyReading applies to the whole document, other options such as wdAllowOnlyFormFields can be applied to particular sections.

    StuartR

  4. #4
    3 Star Lounger
    Join Date
    Aug 2004
    Posts
    361
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking Down a Word Document (Word 2002)

    Tried your suggestion. However this does not appear to to protect the document. When I ran the macro, saved the document,closed it and when reopened it did not need a password to access. The only thing that I noticed is that the TRK shows up at the bottom and any changes that I make are in red and underlined.

    I also noticed that if I went to TOOLs, I find Unprotect Document which when clicked then asks for a password.

    What I want is a method of making sure that no changes are made to the document.

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Locking Down a Word Document (Word 2002)

    It certainly works the way you want in Word 2003, but this may be one of the things that changed for that version.

    Have you tried HansV's suggestion of using wdAllowOnlyFormFields, that should prevent edits.

    StuartR

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

    Re: Locking Down a Word Document (Word 2002)

    Reading view was introduced in Word 2003, so wdAllowOnlyReading doesn't exist. If the OP doesn't require explicit declarations (almost nobody does, despite our repeated warnings <img src=/S/sad.gif border=0 alt=sad width=15 height=15>), it'll be interpreted as 0 = wdAllowOnlyRevisions.

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

    Re: Locking Down a Word Document (Word 2002)

    Kiazd-

    It's hard to tell from your orginal question which of Word's types of protection you want or need. If, as Hans suggested, you use "ActiveDocument.Protect Type:=wdAllowOnlyFormFields", then the anyone can open the document, but nobody can edit it (unless they use the password to turn it off, which you already discovered.)

    However, if what you want is to keep people from opening the file, then you need to use "ActiveDocument.Password = passwprd". This approach, though, only keeps people from opening the file; once it's opened, they can do whatever they want, unless you use it in conjunction with the option mentioned above.

    There is also a third option that forces the document to open as read-only ("ActiveDocument.WritePassword = passwword"), but this is kinda lame for your intent (or so it sounds), because a user only has to perform a "Save As..." to produce an editable copy of the document, which, I assume, could then be saved over your original.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

Posting Permissions

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