Consulting

Results 1 to 3 of 3

Thread: Solved: Protecting Sheets With a Password

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location

    Solved: Protecting Sheets With a Password

    I use the sub below that mdmackillop created to protect and unprotect my sheets so code will run. Now I want to password protect the sheets. If I protect the sheet with "pword" as my password and then activate the sub below, it works fine, it unprotects the sheets using the password. The problem lies when the sub protects the sheets, it will not protect the sheets with a password. I want the sheets to be password protected all of the time. I can't figure it out. Any ideas?

    [VBA]
    Sub DoProtect(x As Boolean)
    For Each Sh In Worksheets
    If x = False Then Sh.Unprotect password:="pword"
    If x = True Then Sh.Protect password:="pword"
    Next
    End Sub
    [/VBA]

    Thanks
    Gary

  2. #2
    Gary

    Worked for me. Protected the sheets and I could unprotect manually using pword.....


    Tony

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    323
    Location
    Hello again Tony, my mistake. My sub calls another sub that unlocks the sheets and does not password protect. I threw on the password and it works. Thanks for loooking at it.

    Gary

Posting Permissions

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