Lock Tabs for specific users

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
954
Office Version
  1. 365
Platform
  1. Windows
Is it possible to not allow a specific user to view specific tabs and only see others w/o actually hiding the tabs and creating a password?

Any workaround for this?

I'm trying to save myself the time of hiding and unhiding tabs so frequently.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
One way to do this is to put two CommandButtons on a sheet you're not going to hide.
Put these two codes to your buttons and it should work.

Note that the Input Box does not hide the letters you type.

Code:
Private Sub CommandButton1_Click()

'UNLOCK

Dim pass As String

pass = InputBox("Enter password:")

'   If Cancel is pressed:
    If StrPtr(pass) = 0 Then Exit Sub
       
'   Correct password, unprotects the workbook and makes Sheet2 visible:
    If pass = "password" Then
        ThisWorkbook.Protect Password:="password", Structure:=False, Windows:=False
        Sheets("Sheet2").Visible = True
        MsgBox "Sheet is now visible"
    Else
'   Wrong password:
        MsgBox "Wrong password"
        Exit Sub
    End If

End Sub

Private Sub CommandButton2_Click()
    
'LOCK
    
'    Hides Sheet2 and protects the workbook so the _
     sheet is not visible without password.
    
     Sheets("Sheet2").Visible = xlVeryHidden
     ThisWorkbook.Protect Password:="password", Structure:=True, Windows:=True
     MsgBox "Sheet is now hidden"
    
End Sub
Another way (better imo) is to make your own userform. In that case you can also use password characters to hide what you're typing.
 
Upvote 0
One way to do this is to put two CommandButtons on a sheet you're not going to hide.
Put these two codes to your buttons and it should work.

Note that the Input Box does not hide the letters you type.

Code:
Private Sub CommandButton1_Click()

'UNLOCK

Dim pass As String

pass = InputBox("Enter password:")

'   If Cancel is pressed:
    If StrPtr(pass) = 0 Then Exit Sub
       
'   Correct password, unprotects the workbook and makes Sheet2 visible:
    If pass = "password" Then
        ThisWorkbook.Protect Password:="password", Structure:=False, Windows:=False
        Sheets("Sheet2").Visible = True
        MsgBox "Sheet is now visible"
    Else
'   Wrong password:
        MsgBox "Wrong password"
        Exit Sub
    End If

End Sub

Private Sub CommandButton2_Click()
    
'LOCK
    
'    Hides Sheet2 and protects the workbook so the _
     sheet is not visible without password.
    
     Sheets("Sheet2").Visible = xlVeryHidden
     ThisWorkbook.Protect Password:="password", Structure:=True, Windows:=True
     MsgBox "Sheet is now hidden"
    
End Sub
Another way (better imo) is to make your own userform. In that case you can also use password characters to hide what you're typing.

thanks for the help. i'll try both and see which works best!
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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