On Passwords...but not against the forum rules

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Hi,
How can I allow the user to give his own password, other than using
If PW<>"password" then Exit Sub
like code.

I would like to
1)get password from the user and store it and
2)then check it with the password next time given by the user

TIA
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
See if this gets you started:

Code:
Sub StorePassword()
    Dim Ans As Variant
    Ans = InputBox("Choose a password", "Password")
    If Ans = "" Then Exit Sub
    ThisWorkbook.Names.Add Name:="Password", RefersTo:=Ans
    ThisWorkbook.Names("Password").Visible = False
End Sub

Sub GetPassword()
    Dim Test As Name
    Dim Ans As Variant
    On Error Resume Next
    Set Test = ThisWorkbook.Names("Password")
    If Err <> 0 Then
        Err.Clear
        MsgBox "No password set"
        Exit Sub
    End If
    On Error GoTo 0
    Ans = InputBox("Enter password", "Password")
    If Ans = "" Then
        Exit Sub
    ElseIf Ans = Evaluate("=Password") Then
        MsgBox "Password correct"
    Else
        MsgBox "Incorrect password"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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