Ciao max_max,
In the attached workbook, the UserForm has been modified for the password. The UserForm is modal, the close X has been removed, closing the Userform using ALT+F4 is disabled, and the user's login Id is used to lookup the password on a new sheet "Elenco".
This sheet holds the allowed user ids and their passwords. If the password and user id do not match then the workbook closes. You should set this sheet's Visible property to xlSheetVeryHidden. This prevents the user from making the worksheet visible. This property can only be changed using the VB Editor. You can change it to xlSheetVisible when you need to edit the list.
The workbook closing feature has been disabled to allow you to setup the user ids and passwords. Once you have done this, you will need to edit the OK button code on the UserForm. Remove the comment character from the beginning of the line marked in bold and save the change.
Private Sub CommandButton1_Click()
' OK Button
Dim pwd As Variant
Dim Rng As Range
Dim RngEnd As Range
Dim UserId As String
Dim Wks As Worksheet
Set Wks = Worksheets("Elenco")
Set Rng = Wks.Range("A2:B2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then GoTo CloseForm Else Set Rng = Wks.Range(Rng, RngEnd)
' Look up the user id and password.
UserId = Environ("USERNAME")
pwd = Application.VLookup(UserId, Rng, 2, 0)
If pwd = TextBox1 Then
MsgBox "Login Successful!"
Else
MsgBox "Login Failed. This Workbook will now Close.", vbExclamation + vbOKOnly
' Remove the comment character (single quote) from the line below after you have edited Elenco.
'ThisWorkbook.Close SaveChanges:=False
End If
CloseForm:
Unload Me
End Sub
Bookmarks