惊了!每天按时下班的男同事,私下竟用Excel搞「多人运动」!【excel教程】
全套Excel视频教程,扫码观看




Private Sub CommandButton1_Click()Dim j, i As Integermaxr = Application.CountA(Sheets("权限表").Range("A:A"))maxc = Application.CountA(Sheets("权限表").Range("1:1"))If TextBox1.Value = "" Then MsgBox "用户名不能为空", vbInformation, "注意": Exit SubIf TextBox2.Value = "" Then MsgBox "密码名不能为空", vbInformation, "注意": Exit SubFor 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 IfNext iMsgBox "用户名或密码错误!"End SubPrivate Sub CommandButton2_Click()Application.DisplayAlerts = FalseUnload MeApplication.Visible = TrueApplication.QuitApplication.EnableEvents = FalseEnd SubPrivate Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode <> 1 Then Cancel = TrueEnd SubPrivate Sub Workbook_BeforeClose(Cancel As Boolean)Application.DisplayAlerts = FalseSheets(1).Visible = xlSheetVisibleDim sht As WorksheetFor Each sht In WorksheetsIf sht.Name <> "权限表" Thensht.Visible = xlSheetVeryHiddenElsesht.SelectCells.EntireColumn.Hidden = Truepw = "excelinexcel"sht.Protect Password = pwsht.EnableSelection = xlNoSelectionEnd IfNextApplication.Visible = FalseThisWorkbook.Close savechanges:=TrueEnd SubPrivate Sub Workbook_Open() Application.DisplayAlerts = False Application.EnableCancelKey = xlDisabled Application.Visible = False UserForm1.ShowEnd Sub

Excel教程相关推荐
VBA实战入门教程(四):判断位数、奇偶性、迟到早退等,都得用它!

让工作提速百倍的「Excel极速贯通班」
赞 (0)
