|
回复 long826121 的帖子
请重新下载吧!
增加了 禁用窗体(关闭)按键!
- Dim R%, C%
- Private Sub CommandButton1_Click() '进入验证
- Dim arr, x%
- If Len(ComboBox1.Text) = 0 Or Len(TextBox2.Text) = 0 Then
- MsgBox "用户名或密码不能为空", , "提示"
- Exit Sub
- End If
- arr = Sheets("sheet2").Range("A4:D" & R).Value
- For x = 1 To UBound(arr)
- If arr(x, 1) = ComboBox1.Value Then '对比用户名
- If TextBox2.Text = arr(x, 4) Then '对比密码
- Exit For
- Else
- C = C + 1
- If C >= 3 Then
- MsgBox "密码输错3次了,系统将退出"
- ActiveWorkbook.Close True
- Else
- MsgBox "您输入的用户或密码有误,第" & C & "次"
- Exit Sub
- End If
- End If
- End If
- Next x
- Unload Me '删除窗体
- If TextBox4.Value = "生产部" Then
- Sheets("sheet3").Visible = True
- Sheets("sheet3").Select
- ElseIf TextBox4.Value = "统计部" Then
- Sheets("sheet4").Visible = True
- Sheets("sheet4").Select
- ElseIf TextBox4.Value = "销售部" Then
- Sheets("sheet5").Visible = True
- Sheets("sheet5").Select
- ElseIf TextBox4.Value = "管理部" Then
- Sheets("sheet6").Visible = True
- Sheets("sheet6").Select
- End If
- End Sub
- Private Sub CommandButton2_Click() '退出 关闭
- ActiveWorkbook.Close True
- End Sub
- Private Sub ComboBox1_Click()
- TextBox3.Text = ComboBox1.List(ComboBox1.ListIndex, 1) '取列表第2列内容(级别)
- TextBox4.Text = ComboBox1.List(ComboBox1.ListIndex, 2) '取列表第3列内容(部分)
- End Sub
- Private Sub UserForm_Initialize() '窗体 初始化
- Dim SH%
- For SH = 2 To Sheets.Count
- Sheets(SH).Visible = False '隐藏工作表
- Next SH
- R = Sheet2.Range("A65536").End(xlUp).Row
- ComboBox1.RowSource = "Sheet2!$A$4:$C$" & R '导入数据
- ComboBox1.Style = fmStyleDropDownList '只能选取列表内容
- TextBox3.Locked = True '不可修改
- TextBox4.Locked = True
- End Sub
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
- If CloseMode = 0 Then Cancel = 1 '禁用 用户在 UserForm.上选择“控制”菜单中的“关闭”命令
- End Sub
复制代码
|
|