|
楼主 |
发表于 2022-7-21 15:41
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub CommandButton1_Click()
Dim j, i As Integer
maxr = Application.CountA(Sheets("权限表").Range("A:A"))
maxc = Application.CountA(Sheets("权限表").Range("1:1"))
If TextBox1.Value = "" Then MsgBox "用户名不能为空", vbInformation, "注意": Exit Sub
If TextBox2.Value = "" Then MsgBox "密码名不能为空", vbInformation, "注意": Exit Sub
For i = 2 To maxc
u = Worksheets("权限表").Cells(1, i)
k = Worksheets("权限表").Cells(2, i)
If TextBox1.Text = u And TextBox2.Text = k Then
Unload Me
Application.Visible = True
Application.EnableCancelKey = xlInterrupt
For j = maxr To 3 Step -1
ThisWorkbook.Activate
If Sheets("权限表").Cells(j, i) = "是" Then
Sheets(j - 2).Visible = xlSheetVisible
Else
Sheets(j - 2).Visible = xlSheetVeryHidden
End If
Next j
If Sheets("权限表").Visible = xlSheetVisible Then
pw = "excelinexcel"
Sheets("权限表").Unprotect Password = pw
Cells.Select
Selection.EntireColumn.Hidden = False
End If
Exit Sub
End If
Next i
MsgBox "用户名或密码错误!"
End Sub |
|