Private Sub CommandButton1_Click() Dim MyLoginStatus As Single MyLoginStatus = 0 For i = 2 To ThisWorkbook.Sheets("UserLoginInfor").UsedRange.Rows.Count If (Trim(ThisWorkbook, Sheets("UserLoginInfor").Cells(i, 1).Value)) = Trim(TextBox1.Value) And (Trim(ThisWorkbook.Sheets("UserLoginInfor").Cells(i, 2).Value)) = Trim(TextBos2.Value) Then MyLoginSatus = MyLoginStatus + 1 If (Trim(ThisWorkbook.Sheets("UserLoginInfor").Cells(i, 3).Value) = "最高权限") Then ThisWorkbook.Sheets("UserLoginInfor").Visible = True Else ThisWorkbook.Sheets("UserLoginInfor").Visible = False End If End If Next i If (MyLoginStatus >= 1) Then MsgBox "登陆成功", vbInformation, "系统消息" UserForm1.Hide Else MsgBox "错误的用户名和密码", vbCritical, "系统消息" End If End Sub