我的Excel工作簿中有5个工作表,但我想用密码专门保护第3和第5个工作表。有下面只保护一张纸的宏。需要添加什么来保护多张纸张而不是所有纸张。请指导我。
先谢谢!!
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MySheets As String, Response As String
MySheet = "Sheet1"
If ActiveSheet.Name = MySheet Then
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "pass" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet).Visible = True
End Sub
答案 0 :(得分:1)
试试这个:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MySheets As String, Response As String
MySheet = ActiveSheet.Name
Select Case MySheet
Case "Sheet1", "Sheet3", "Sheet5"
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "pass" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End Select
Sheets(MySheet).Visible = True
End Sub
但硬编码密码不会让它变得安全。