我使用此密碼來保護兩頁。
由於某些奇怪的原因,我可以隱藏「Sheet1」而不是「Sheet2」,因爲它總是可見的。
行Sheets(MySheet2).Visible = True
的原因是,如果有人輸入了錯誤的密碼,它不會立即隱藏它。Excel密碼保護表
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim MySheets As String, Response As String
MySheet = "Sheet1"
MySheet2 ="Sheet2"
If ActiveSheet.Name = MySheet Then
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "MyPass" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet).Visible = True
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If ActiveSheet.Name = MySheet2 Then
ActiveSheet.Visible = False
Response = InputBox("Enter password to view sheet")
If Response = "MyPass" Then
Sheets(MySheet2).Visible = True
Application.EnableEvents = False
Sheets(MySheet2).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet2).Visible = True
End Sub
在那裏工作簿中只有兩個表?我沒有測試過你的代碼,但我會想象你正在試圖隱藏這兩個表單,從而導致錯誤。 – Miguel