Password Protected Tab Macro Help

welshraz

New Member
Joined
Apr 29, 2016
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hello again,

I have password protected a tab using the following:

Sub OpenWS()
Dim S As String
S = InputBox("Enter Password")
If S = vbNullString Then
Exit Sub
ElseIf S <> "teamlongdrop" Then
Exit Sub
Else
Worksheets("Contacts").Visible = xlSheetVisible
Sheets("Contacts").Select
End If
End Sub

I have linked this to a button but it asks for the password every time it is pressed. Is there a way of making it so that it only asks for the password if the tab is still hidden? Essentially, I want it to ask for a password the first time the button is pressed after the workbook is opened, but after that point it for it to just take you to the "Contacts" tab?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How about
VBA Code:
Sub OpenWS()
Dim S As String
If Sheets("Contacts").Visible = xlSheetVisible Then Exit Sub
S = InputBox("Enter Password")
If S = vbNullString Then
Exit Sub
ElseIf S <> "teamlongdrop" Then
Exit Sub
Else
Worksheets("Contacts").Visible = xlSheetVisible
Sheets("Contacts").Select
End If
End Sub
 
Upvote 0
Another way.
VBA Code:
Sub OpenWS()
 If Sheets("Contacts").Visible = True Then Sheets("Contacts").Activate: Exit Sub
 Sheets("Contacts").Visible = InputBox("Enter Password") = "teamlongdrop": Sheets("Contacts").Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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