|
我设置了变量,为啥还不给我运行。
以下是代码。
- Option Explicit
- Private Sub CommandButton1_Click()
- If ComboBox1.Value = "" Then
- MsgBox "用户名不能为空!"
- ElseIf TextBox2 = "" Then
- MsgBox "密码不能为空!"
- Exit Sub
- End If
- Dim rng As Range
- Set rng = shtAdmin.Range("A:A").Find(what = Me.ComboBox1.Value, lookat:=xlWhole)
- If rng Is Nothing Then
- MsgBox "用户不存在!请重新输入!"
- Exit Sub
- Else
- If rng.Offset(0, 1).Value & "" = TextBox2 Then
- '密码正确 分管理员和普通人员
- 成功登录 rng
- Else
- '密码错误
- MsgBox "密码错误!请重新输入!"
- Exit Sub
- End If
- End If
- End Sub
- Sub 成功登录(rng As Range)
- Select Case rng.Value
- Case "admin"
- shtAdmin.Visible = xlSheetVisible '显示出管理员可见的表
- shtAdmin.Activate
- MsgBox "欢迎管理员登录"
- Case Else '其他权限 可分多级
- Sheet1.Activate
- Sheet2.Activate
- Sheet3.Activate
- Sheet4.Activate
- Sheet1.Activate
- Sheet5.Activate
- Sheet6.Activate
- Sheet7.Activate
- MsgBox "欢迎员工" & rng.Value & "登录!"
- End Select
- Application.Visible = True
- Unload Me
- End Sub
- Private Sub CommandButton2_Click()
- ThisWorkbook.Close False
- Application.Quit
- Unload Me
- End Sub
- Private Sub UserForm_initialize()
- Dim i
- For i = 2 To shtAdmin.UsedRange.Rows.Count
- If shtAmin.Cells(i, 1) <> "" Then
- Me.ComboBox1.AddItem shtAdmin.Cells(i, 1)
- End If
- Next
- ComboBox1.Value = shtAdmin.Cells(2, 1)
- End Sub
- Public Sub 登陆初始化()
- '把权限高级的部分隐藏起来
- shtAdmin.Visible = xlSheetVeryHidden '彻底隐藏
- End Sub
- Private Sub userform_queryclose(cancel As Integer, closemode As Integer)
- If closemode <> 0 Then
- cancel = 1
- End If
- End Sub
复制代码
|
|