title: How to password protect and hide all sheets except two worksheets?
body: <p>I came across the following VBA function within <a href="https://answers.microsoft.com/en-us/office/forum/office_2010-excel/how-to-password-protect-a-single-tab-in-a-workbook/934ceaeb-a6e8-400b-8123-0e2d393ff94b?db=5" rel="nofollow noreferrer">this forum</a> that works for password protecting one sheet, but I would like to password protect all sheets except two sheets: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have five sheets in my workbook ("Sheet1","Sheet2","Sheet3","Sheet4","Sheet5") and I would like all sheets to be password protected and hidden except Sheet1 and Sheet2. In other words, Sheet3, Sheet4, and Sheet5 should all be password protected with the above code</p>
  
  <p>I've updated the function to be as follows, but it does not even show any other sheets even after entering the correct password </p>
  
  <pre><code>Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  Dim MySheets As String, Response As String
  MySheet = "Sheet1"
  MySheet2 = "Sheet2"
  If ActiveSheet.Name &lt;&gt; MySheet And ActiveSheet.Name &lt;&gt; MySheet2 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
  Sheets(MySheet2).Visible = True
  
  End Sub
  </code></pre>