+ Reply to Thread
Results 1 to 2 of 2

Protect Sheet With Password Using VBA

  1. #1
    Registered User
    Join Date
    12-03-2006
    Posts
    1

    Protect Sheet With Password Using VBA

    Just wondering if any suggestions exist for why this code, once executed, leaves the sheet not requiring a password to remove the protection:

    Sub ProtectOn()

    ActiveSheet.Outline.ShowLevels RowLevels:=1
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.Protect Password:="test"
    End Sub

    So the sheet ends up protected, but all a user has to do is access the Tools>Protection>Unprotect Sheet menu to take the sheet protection off - the " ActiveSheet.Protect Password:="test" " statement is not executing. I'm calling this procedure from one other code initiated procedure in Excel 2003. Any advice or guidance anyone would have would be greatly appreciated!

    Thanks,
    Trish

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Trish
    Just wondering if any suggestions exist for why this code, once executed, leaves the sheet not requiring a password to remove the protection:

    Sub ProtectOn()

    ActiveSheet.Outline.ShowLevels RowLevels:=1
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.Protect Password:="test"
    End Sub

    So the sheet ends up protected, but all a user has to do is access the Tools>Protection>Unprotect Sheet menu to take the sheet protection off - the " ActiveSheet.Protect Password:="test" " statement is not executing. I'm calling this procedure from one other code initiated procedure in Excel 2003. Any advice or guidance anyone would have would be greatly appreciated!

    Thanks,
    Trish
    Hi,

    Move the 'Password' up a line, the sheet is already protected and it gets ignored.

    hth
    ---
    Si fractum non sit, noli id reficere.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1