|
Para que funciones, debes tener una hoja llamada "Usuarios", un userform1, dos textbox llamados user y pass dos botones, Ok y Cierra y pegar este codigo en userform:
'En el evento Workbook_open de Thisworkbook debes poner este codigo
userform1.show
Private Sub Cierra_Click()
If MsgBox("Salir de Excel?", vbYesNo) = vbYes Then
Application.Quit
Unload Me
Else
Unload Me
End If
End Sub
Private Sub Ok_Click()
Application.ScreenUpdating = False
Sheets("Usuarios").Visible = True
Sheets("Usuarios").Select
Range("A2", Range("A65536").End(xlUp)).Select
If Selection.Find(User.Text, , , xlWhole) Is Nothing Then
GoTo NoEncontrado
Else
Selection.Find(User.Text, , , xlWhole).Select
'MsgBox User & " - " & Pass
If ActiveCell.Value = User And ActiveCell.Offset(0, 1).Value = Pass Then
MsgBox "Bienvenido " & User
Unload UserForm1
' Pone en la barra de Excel de arriba el nombre del Usuario que entró
Application.Caption = User
Else
NoEncontrado:
MsgBox "Nombre de Usuario o Contraseña Incorrecta, Verifique el uso correcto de Mayusculas y Minusculas"
User = Empty
Pass = Empty
User.SetFocus
Sheets("acceso").Select
End If
End If
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing with the Close box in the title bar.
Cancel = False
If CloseMode <> 1 Then Cancel = True
UserForm1.Caption = "Debe usar el boton Cerrar del Formulario"
End Sub
Cualquier duda me dices, saludos
|