我有3张excel工作簿,并且想要用密码保护第二张(sheet2)。 我想从sheet1或sheet3切换到sheet2时,它会询问密码,除非确认密码,否则sheet2的所有单元格都是不可见的。
你可以帮我做这个任务吗? 提前致谢答案 0 :(得分:0)
一个简单的谷歌搜索提供了以下来自Microsoft的代码..
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 = "MyPass" Then
Sheets(MySheet).Visible = True
Application.EnableEvents = False
Sheets(MySheet).Select
Application.EnableEvents = True
End If
End If
Sheets(MySheet).Visible = True
End Sub