代码:
[Visual Basic] 纯文本查看 复制代码Option Explicit
Dim blnLogin As Boolean
Private Sub CommandButton1_Click()
Dim username As String
Dim password As String
Dim rngName As Range
username = Me.txtUserName.Text
password = Me.txtPassword.Text
Set rngName = Sheet2.Columns(1).Find(What:=username, lookat:=xlWhole)
If Not rngName Is Nothing Then
If password = rngName.Offset(0, 1).Value Then
blnLogin = True
Unload Me
Exit Sub
End If
End If
MsgBox "用户名或密码错误!"
End Sub
Private Sub UserForm_Initialize()
blnLogin = False
End Sub
密码储存在Sheet2,对应为:
A1 username
B1 password
A2 jay
B2 123
在窗体中,用户名输入jay,密码输入123或用户名输入username,密码输入password均判定为错误。