See Worksheet Tab, but can't Activate without Password Inputted

RMXByker

New Member
Joined
Apr 1, 2010
Messages
38
I have a worksheet labeled ADMIN that I would like to be seen in the worksheet tabs at the bottom of the workbook. However, I would like a password input to be required if the user tries to activate this tab. Is this possible? I thought potentially have some code in the worksheet activate tab but unsure. Anyone do this before?
 

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.
Hello,

Put this code in the sheet module that you would like protected:
Code:
Private Sub Worksheet_Activate()
Dim pw As String
Dim check As String

pw = "My Password"

Me.Visible = False
check = Application.InputBox("Enter Password to access sheet " & Me.Name & ".")
If check = pw Then
    Me.Visible = True
    Application.EnableEvents = False
    Me.Activate
    Application.EnableEvents = True
End If

End Sub

Update the pw variable (line 4) to whatever password you would like.

Let me know if you have any questions.
 
Last edited:
Upvote 0
Since you said:

I have a worksheet labeled ADMIN that I would like to be seen in the worksheet tabs at the bottom of the workbook. However, I would like a password input to be required if the user tries to activate this tab. Is this possible?

Try this:

If the password is not correct the script will Activate sheet(1)

So we will assume sheet named "Admin" is not Sheet(1)

Or modify script to activate some other sheet

Right click on the Admin sheet tab and paste in this script.

Code:
Private Sub Worksheet_Activate()
Dim ans As String
ans = InputBox("Enter Password")
If ans = "Test" Then
Else
MsgBox "Wrong Password"
Sheets(1).Activate
End If
Exit Sub
End Sub
 
Upvote 0
Thanks for your guys help. One issue with what is shown above is that the user could still see the worksheet even with the popup. They just couldn't do anything with it. So I ended up simply adding a "Shape" hiding everything and a form popup as well. Then once the password is correct, it unlocks the sheet and hides the shape. Once locked, it protects the sheet and sets the visibility of the shape.

Thanks everyone. Below is the code I used in case anyone wants to tinker with it later one.

Sheet Code
Code:
Private Sub Worksheet_Activate()

    Application.ScreenUpdating = False
    ADMINLock.Show


End Sub

Form Code
Code:
Private Sub ADMINLockButton_Click()


    Sheets("ADMIN").Select
    ActiveSheet.Shapes("Rectangle 3").Visible = True
    Worksheets("ADMIN").Protect Password:="PASSWORD 2"


    Worksheets("Sheet 1").Activate
    Range("A10").Select
    
    Me.Hide
    Application.ScreenUpdating = True
    
End Sub




Private Sub ADMINUnlockButton_Click()
    If ADMINUnlock.Value = "PASSWORD" Then
        
        Worksheets("ADMIN").Unprotect Password:="PASSWORD2"
        Me.Hide
        Sheets("ADMIN").Select
        ActiveSheet.Shapes("Rectangle 3").Visible = False
        Range("B2").Select
                
    Else
        MsgBox "You do not have Admin Unlock permission"
        Worksheets("Sheet 1").Activate
        Range("A10").Select


    End If
    
    Me.Hide
    Application.ScreenUpdating = True
        
End Sub


Private Sub UserForm_Initialize()
With Me
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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