|
本帖最后由 caizhiliang 于 2019-11-25 11:50 编辑
老师您好!
这是一段登录窗体的代码
想增加限制登录次数为3次
请问怎么修改
Private Sub CommandButton1_Click() '''''''系统登陆确定按钮
Dim s$
Dim n%, i%, j%, k%
Unload Login
k = Sheet1.Range("iv2").End(xlToLeft).Column '现在的工作表
For i = 4 To k '清除原有数据
Sheet1.Cells(2, i) = ""
Next
n = ActiveWorkbook.Sheets.Count '获取工作薄中工作表数
For i = 1 To n '在2 行显示工作表名称
Sheet1.Cells(2, i + 3) = Sheets(i).Name
Next
Application.ScreenUpdating = False
Sheet1.Range("A2").Value = Me.ComboBox1.Text '获得输入的密码
s = Sheet1.Range("A2").Value & " " & Application.VLookup(Me.ComboBox1.Text, Sheet1.Range("$A$4:$C" & Sheet1.Range("A65536").End(xlUp).Row), 3, 0) '全称谓
s1 = Application.VLookup(Sheet1.Range("$A$2"), Sheet1.Range("$A$4:$C" & Sheet1.Range("A65536").End(xlUp).Row), 3, 0) '职位
If Me.TextBox1.Text = Sheet1.Range("B2").Value Then '密码正确
If (s1 = "系统管理员") Then
Set Ctl = Application.CommandBars.FindControl(ID:=847)
Ctl.OnAction = "" '管理员允许删除工作表
End If
Application.WindowState = xlMaximized '窗口最大化
MsgBox s & " ,欢迎你使用本系统!", vbInformation, "欢迎"
Application.Visible = True '工作簿可见
For i = 1 To ActiveWorkbook.Sheets.Count '工作薄中工作表数
If (Sheet1.Cells(2, i + 3).Value <> "Macro1") Then
Worksheets("" & Sheet1.Cells(2, i + 3).Value).Visible = True '全部显示(不显示宏表)
End If
Next
n = Application.Match(Me.ComboBox1.Text, Sheet1.Range("$A$4:$a" & Sheet1.Range("A65536").End(xlUp).Row), 0) + 3 '当前操作员在表格里面的行号
For i = 1 To ActiveWorkbook.Sheets.Count '工作薄中工作表数
If (Sheet1.Cells(n, i + 3) = "可") Then '根据是否为“可”决定
If (Sheet1.Cells(2, i + 3).Value <> "Macro1") Then
Worksheets("" & Sheet1.Cells(2, i + 3).Value).Visible = True '显示
End If
Else
If (Sheet1.Cells(2, i + 3).Value <> "Macro1") Then '因为宏表已经隐藏
Worksheets("" & Sheet1.Cells(2, i + 3).Value).Visible = xlSheetVeryHidden '深度隐藏工作表
End If
End If
Next
Else
MsgBox "密码错误,你无权使用本系统!", vbExclamation, "系统提示"
Application.DisplayAlerts = False '不显示对话框
ThisWorkbook.Close savechanges:=False
End If
Application.ScreenUpdating = True
End Sub
|
|