Error when using password to hide tabs

Hooqa13

New Member
Joined
Jul 3, 2014
Messages
19
I am trying to create a spreadsheet that people can use one password to show all hidden sheets in the workbook and another password that only shows 2 of the hidden sheets. This 2nd password is very important so that users cannot see the hidden tabs or any of the information on those tabs. The VBA code I have works for the first password and shows all hidden sheets but I get an error when I try to use the 2nd limited password.

The error I receive is Run-time error '32809': Application-defined or object-defined error

The VBA code I have linked to a button is below. Range D1 refers to the password "secure" and Range D2 refers to the password "VP". It's the VP password that is not working...

Code:
Private Sub Password_Click()

'Opens the tool based on password given in instruction tab-----------------------------

Dim msg
    
    Application.ScreenUpdating = False
    
    Select Case PasswordBox.Text
    
'VP Access Password

    Case Sheets("Security").Range("D1").Text
        PasswordBox.Text = ""
        
        Sheets("Instructions").Visible = True
        Sheets("Budget Analysis").Visible = True
        Sheets("Position Review").Visible = True
        ActiveWorkbook.Protect Password:="secure", Structure:=True, Windows:=False
             
'Admin Access Password

    Case Sheets("Security").Range("D2").Text
        PasswordBox.Text = ""
        
        ActiveWorkbook.Unprotect Password:="secure"
        Dim ws As Worksheet
            For Each ws In Worksheets
            ws.Visible = True
            ws.Unprotect Password:="secure"
            Next

'Hide

    Case "hide"
        PasswordBox.Text = ""

        ActiveWorkbook.Unprotect Password:="secure"
        Dim ws1 As Worksheet
        Dim AER As AllowEditRange
            For Each ws1 In Worksheets
            If ws1.Visible = xlSheetVisible Then ws1.Select
            ws1.Unprotect Password:="secure"
            For Each AER In ws1.Protection.AllowEditRanges
            AER.Delete
            Next AER
            If ws1.Name <> Sheets("Instructions").Name Then ws1.Visible = xlSheetVeryHidden
            Next ws1
            
    End Select
    
Application.ScreenUpdating = True
    
End Sub
 
Last edited by a moderator:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You may need to add
Code:
ActiveWorkbook.Unprotect Password:="secure"

to the VP case.
 
Last edited:
Upvote 0
I know this sounds silly but make sure the spelling on the tab name doesn't have an extra space in between or at the end and the letters are identical.
 
Upvote 0
No and I triple checked the spelling thinking that might have been it too! :sigh: I'm going to re-create the entire thing, maybe the file got corrupted somehow but please let me know if you have more suggestions :)
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top