Excelerate2
New Member
- Joined
- Mar 18, 2022
- Messages
- 25
- Office Version
- 365
- 2019
- 2016
- 2010
- Platform
- Windows
I had a question and have been trying to add the ability to use the same code below but with adding a user defined password and/or without using a password (similar to the Excel's own 'protect/unprotect icon' which allows you to optionally use your own password or none at all)
I am stumped but if anyone knows how to modify it would be great!
Here is the code below (it has a fixed password: "123", but I would like the user to be able to create their own password, and maybe also opt for blank or no password:
--------
Option Explicit
Public Const conSheetPassword As String = "123"
Sub ViewSheet()
Dim userInput As Variant
userInput = InputBox( _
Prompt:="Input a password to unlock the worksheets.", _
Title:="Password Input", _
Default:="Password")
If LCase(Trim(userInput)) = LCase(conSheetPassword) Then
' Pass - all is good.
Sheet2.Visible = xlSheetVisible
Sheet6.Visible = xlSheetVisible
Sheet2.Select
Else
MsgBox "Incorrect password. Access Denied."
End If
End Sub
-------------------------
Sub HideSheet()
Sheet2.Visible = xlSheetVeryHidden
Sheet6.Visible = xlSheetVeryHidden
Sheet1.Select
End Sub
-------
I am stumped but if anyone knows how to modify it would be great!
Here is the code below (it has a fixed password: "123", but I would like the user to be able to create their own password, and maybe also opt for blank or no password:
--------
Option Explicit
Public Const conSheetPassword As String = "123"
Sub ViewSheet()
Dim userInput As Variant
userInput = InputBox( _
Prompt:="Input a password to unlock the worksheets.", _
Title:="Password Input", _
Default:="Password")
If LCase(Trim(userInput)) = LCase(conSheetPassword) Then
' Pass - all is good.
Sheet2.Visible = xlSheetVisible
Sheet6.Visible = xlSheetVisible
Sheet2.Select
Else
MsgBox "Incorrect password. Access Denied."
End If
End Sub
-------------------------
Sub HideSheet()
Sheet2.Visible = xlSheetVeryHidden
Sheet6.Visible = xlSheetVeryHidden
Sheet1.Select
End Sub
-------