我在excel工作簿中有5個工作表,但我想特別保護第三和第五工作表的密碼。

[英]i have 5 worksheets in my excel workbook but i want to specifically protect 3rd and 5th worksheets with password


I have 5 worksheets in my excel workbook but I want specifically protect 3rd and 5th worksheets with password. Have below macro which protects only one sheet. what needs to be added to protect more than one sheet but not all sheets. Kindly guide me.

我的excel工作簿里有5個工作表,但是我特別想用密碼保護第3和第5個工作表。在宏下面只有一個保護單。需要添加什么來保護一個以上的頁,而不是所有的頁。請指引我。

Thanks in Advance!!

提前謝謝! !

      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

1 个解决方案

#1


1  

Try this:

試試這個:

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

But hardcoding the password doesnt make it that safe.

但是硬編碼密碼並不那么安全。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/07/06/72fdb9fc4ee0ebfe9837e6589d15e0d6.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com