|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 ivccav 于 2017-12-22 09:48 编辑
不能隐藏所有工作表,以前没用过,现在才知道有这限制。只能把标签也隐藏了。
Private Sub Workbook_Open()
On Error Resume Next
Dim psw$, YN$, sht As Worksheet
ActiveWindow.DisplayWorkbookTabs = False
Line1:
psw = InputBox("请输入你的密码:", "密码输入框")
If psw = "12345" Then
Sheet1.Visible = xlSheetVisible
Sheet1.Activate
ActiveWindow.DisplayWorkbookTabs = True
For Each sht In Worksheets
If sht.CodeName <> "Sheet1" Then sht.Visible = xlSheetVeryHidden
Next
ElseIf psw = "1234" Then
Sheet2.Visible = xlSheetVisible
Sheet2.Activate
ActiveWindow.DisplayWorkbookTabs = True
For Each sht In Worksheets
If sht.CodeName <> "Sheet2" Then sht.Visible = xlSheetVeryHidden
Next
ElseIf psw = "123" Then
Sheet3.Visible = xlSheetVisible
Sheet3.Activate
ActiveWindow.DisplayWorkbookTabs = True
For Each sht In Worksheets
If sht.CodeName <> "Sheet3" Then sht.Visible = xlSheetVeryHidden
Next
ElseIf psw = "12" Then
Sheet4.Visible = xlSheetVisible
Sheet4.Activate
ActiveWindow.DisplayWorkbookTabs = True
For Each sht In Worksheets
If sht.CodeName <> "Sheet4" Then sht.Visible = xlSheetVeryHidden
Next
ElseIf psw = "123456" Then
For Each sht In Worksheets
sht.Visible = xlSheetVisible
sht.Activate
ActiveWindow.DisplayWorkbookTabs = True
Next
Else
YN = MsgBox("密码错误!是否重新输入?", vbYesNo)
If YN = vbYes Then GoTo Line1 Else ThisWorkbook.Close 0
End If
End Sub
|
|