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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Thanks A Lot for this code.
Had a lot of stuff (for me) to play upon.
Thanks A lot
 

Forum statistics

Threads
1,140,944
Messages
5,703,305
Members
421,290
Latest member
james90

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
Top