|
楼主 |
发表于 2021-9-5 15:09
|
显示全部楼层
Private Sub CommandButton1_Click()
On Error GoTo 10 '当姓名与密码不对应时,会出现错误,转到10语句处理
Dim n As String
Set sh = Sheets("员工信息")
na = ComboBox1.Text: ps = TextBox2.Text '取得登录窗口中的姓名与密码
If na = "" Or ps = "" Then MsgBox "未输入用户名或密码,不能登录", , "提示": Exit Sub
s = WorksheetFunction.Match(na, sh.[A:A], 0) '查找用户在A列的位置
n = sh.Cells(s, 2) '取出"设置"表中的权限密码,字符型
If n <> ps Then GoTo 10
Call 隐藏表
'检查一下"设置"表的C列及右边各格中的内容,有内容的,说明可以打开内容所指定的工作表
For i = 3 To 255
b = sh.Cells(s, i).Value
If b = 1 And sh.Cells(1, i) <> "" Then '单元格为1时,表示有权限打开这个表,就让它显示出来
Sheets(sh.Cells(1, i).Value).Visible = -1
End If
Application.Visible = True '显示工作表界面
Next
Unload UserForm1 '退出窗体
Exit Sub
10:
MsgBox "姓名或密码错误,不能登录", , "提示"
End Sub
Sub 隐藏表()
For i = 1 To Worksheets.Count
If Sheets(i).Name <> "主菜单" Then
Sheets(i).Visible = 2
Else
Sheets(i).Visible = -1 '只让"登录"表显示出来
End If
Set Sh7 = Sheet11 '***
With Sheet11
.Range("R2").Value = ComboBox1.Text
.Range("S2").Value = TextBox2.Text
.Range("T2").Value = Now()
End With
Next
End Sub
Private Sub CommandButton2_Click()
Call 隐藏表
End Sub
Private Sub UserForm_Activate()
'窗体出现在屏幕上的位置
Me.Top = 100
Me.Left = 200
For i = 2 To Sheets("员工信息").[a65536].End(xlUp).Row
ComboBox1.AddItem Sheets("员工信息").Cells(i, 1).Value
Next
End Sub
Private Sub form_resize()
'随着窗体大小自动调节图片大小
imag1.Top = 0
imag1.Left = 0
imag1.stretch = True
imag1.Height = Me.ScaleHeight
imag1.Width = Me.ScaleWidth
imag1.Picture = Me.Picture
End Sub
Private Sub UserForm_Initialize()
Dim r
ComboBox1.Clear
ComboBox1.Text = ""
r = Sheet11.Range("A65536").End(xlUp).Row
For i = 2 To r
ComboBox1.AddItem Sheet11.Range("A" & i).Value
Next
ComboBox1.ListIndex = 0
End Sub
|
|