惊了!每天按时下班的男同事,私下竟用Excel搞「多人运动」!【excel教程】
全套Excel视频教程,扫码观看
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
Private Sub CommandButton2_Click()
Application.DisplayAlerts = False
Unload Me
Application.Visible = True
Application.Quit
Application.EnableEvents = False
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Sheets(1).Visible = xlSheetVisible
Dim sht As Worksheet
For Each sht In Worksheets
If sht.Name <> "权限表" Then
sht.Visible = xlSheetVeryHidden
Else
sht.Select
Cells.EntireColumn.Hidden = True
pw = "excelinexcel"
sht.Protect Password = pw
sht.EnableSelection = xlNoSelection
End If
Next
Application.Visible = False
ThisWorkbook.Close savechanges:=True
End Sub
Private Sub Workbook_Open()
Application.DisplayAlerts = False
Application.EnableCancelKey = xlDisabled
Application.Visible = False
UserForm1.Show
End Sub
Excel教程相关推荐
VBA实战入门教程(四):判断位数、奇偶性、迟到早退等,都得用它!
让工作提速百倍的「Excel极速贯通班」
赞 (0)