Unhide worksheets with password in userform

bptaw

Board Regular
Joined
Feb 27, 2017
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
I have an introduction sheet on which I want to place a userform which requires a password to unhide all other sheets which are very hidden. The correct password unhides the sheets and reveals a button link to Sheet2. On saving and closing the workbook all sheets are again hidden so the password is required each time it is opened. I have tried to adapt various similar solutions but am not skilled enough in vba or use of userforms.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I have the following code in my userform button, but nothing happens when I run it
:
Private Sub CommandButton1_Click()
Dim password As String
password = "password"

If TextBox1.Value = password Then
' Unhide sheets
ThisWorkbook.Sheets("Sheet1").Visible = xlSheetVisible
ThisWorkbook.Sheets("Sheet2").Visible = xlSheetVisible
ThisWorkbook.Sheets("Sheet3").Visible = xlSheetVisible
ThisWorkbook.Sheets("Sheet4").visible = xlSheetVisible


' Show button link to Sheet2
Sheet3.Shapes("ButtonLink").Visible = True

' Hide the UserForm
Unload Me
Else
MsgBox "Incorrect password. Please try again."
End If
End Sub
 
Upvote 0
I am making progress with my userform:

Private Sub cmdLogin_Click()

Dim user As String
Dim password As String
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then

Unload Me
' Loop through all worksheets in the workbook
For Each ws In ThisWorkbook.Sheets
' Check if the sheet is very hidden
If ws.Visible = xlSheetVeryHidden Then
' Unhide the sheet
ws.Visible = xlSheetVisible
End If
Next ws


Else

MsgBox "Invalid login credentials. Please try again."

End If


The last part I want to add is that a shape is also made visible as part of this process.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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