打开工作簿,弹出弹窗输入密码,如果密码错误则关闭工作簿
首先在 thisworkbook里设置 当打开工作簿时 执行代码
代码如下:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sht As Worksheet
'隐藏所有表
For Each sht In Sheets
If sht.Name <> “登录界面” Then
sht.Visible = xlSheetVeryHidden
End If
Next
End Sub
Private Sub Workbook_Open()
Dim i
i = InputBox(“请输入密码”)
If i = “123” Then
Sheet1.Visible = xlSheetVisible
Sheet2.Visible = xlSheetVisible
Sheet3.Visible = xlSheetVisible
ElseIf i = “456” Then
Sheet4.Visible = xlSheetVisible
Sheet5.Visible = xlSheetVisible
Sheet6.Visible = xlSheetVisible
Else
MsgBox “密码输入错误”
ThisWorkbook.Close
End If
End Sub
这样输入123后 工作表才会显示出123的内容