本帖最后由 天马 于 2012-7-12 14:49 编辑
sdwffw 发表于 2012-7-10 19:37
i = Sheet5.[A:A].Find(a, Lookat:=xlWhole).Row
代码中的这条查找语句一直发挥作用?
1、这是excel默认的,保留上次查找的记录和匹配格式,对后面的操作没有多在的影响,你若要编辑-查找,可重新设置查找的条件,在查找窗口中点选项进行设置。
2、在编辑查找中若你不要看到系统登录时的用户名,可用循环来代替查找语句来判断密码是否正确来登录。
将窗体中的代码稍改动如下,保留了你原代码注释部分,添加了红色字体部分
Private Sub CommandButton1_Click()
Dim a As String, b As String
Dim i As Integer, ir As Integer
Dim Bol As Boolean
Bol = False
If ComboBox1.Text = "" Or TextBox1.Text = "" Then
MsgBox "请填写齐全!", 1 + 64, "系统登陆"
'TextBox1.SetFocus
Exit Sub
End If
a = ComboBox1.Text
b = TextBox1.Text
' i = Sheet5.[A:A].Find(a, Lookat:=xlWhole).Row
For i = 1 To Sheet5.Range("A65536").End(xlUp).Row
If Sheet5.Cells(i, 1) = a And Sheet5.Cells(i, 2) = b Then '判断用户名和密码是否一致
Bol = True
Exit For
End If
Next i
If Bol Then
Unload UserForm1
MsgBox ComboBox1.Text & "你好,欢迎你进入本系统!", 1 + 64, "欢迎词"
Application.Visible = True
Else
MsgBox "登陆密码错误,请重新输入!"
Exit Sub
End If
If i = 3 Then
For i = 2 To 5
Sheets(i).Visible = xlSheetVisible
Next
ElseIf i = 4 Then
For i = 2 To 4
Sheets(i).Visible = xlSheetVisible
Next
Else
Sheet4.Visible = xlSheetVisible
End If
'If ComboBox1.Text = "" Or TextBox1.Text = "" Then
' MsgBox "请填写齐全!", 1 + 64, "系统登陆"
' TextBox1.SetFocus
'Else
' Sheets("SHEET5").Range("A20") = ComboBox1.Text
' If Sheets("SHEET5").Range("B20") = TextBox1.Text Then
' Unload UserForm1
' MsgBox ComboBox1.Text & "你好,欢迎你进入本系统!", 1 + 64, "欢迎词"
'
' Application.Visible = True
'ActiveWorkbook.Unprotect PASSWORD:="12345"
'Sheets("主界面").Visible = True
' Sheets("主界面").Activate
'Sheets("A").Visible = False
'ActiveWorkbook.Protect PASSWORD:="12345"
' Else
' MsgBox "登陆密码错误,请重新输入!"
' End If
'End If
End Sub
|