用户使用密码仅访问 Excel 中的某些选项卡的 VBA 代码

问题描述 投票:0回答:1

我们有一些以当前格式工作的 VBA 代码,要求用户输入密码,然后根据该密码他们可以访问特定选项卡。

我们需要调整代码,以便用户可以访问 2 个选项卡,例如,我希望 East 的用户访问选项卡“East”和标题为“East_Dashboard”的选项卡 - 我如何调整下面的代码来做到这一点那?

我希望这是可能的...我对 VBA 真的很陌生。

谢谢你

Private Sub Workbook_Open()
Dim pword As String
On Error GoTo endit
  pword = InputBox("Enter Your Password")
  Select Case pword
  Case Is = "EastPassword": Sheets("East").Visible = True
  Case Is = "NorthPassword": Sheets("North").Visible = True
  Case Is = "WestPassword": Sheets("West").Visible = True
  Case Is = "MasterPassword": Call UnHideAllSheets
End Select
Sheets("Welcome").Visible = False
Exit Sub
endit:
MsgBox "Incorrect Password - contact Name"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sht As Worksheet
Application.ScreenUpdating = False
   Sheets("Welcome").Visible = xlSheetVisible
       For Each sht In ActiveWorkbook.Sheets
       If sht.Name <> "Welcome" Then
  sht.Visible = xlSheetVeryHidden
End If
Next sht
Application.ScreenUpdating = True
End Sub
excel vba spreadsheet password-protection
1个回答
0
投票

Select Case
语句的文本更改为:

Select Case pword
  Case "EastPassword": Sheets(Array("East", "East_Dashboard")).Visible = True
  Case "NorthPassword": Sheets(Array("North", "North_Dashboard")).Visible = True
  Case "WestPassword": Sheets(Array("West", "West_Dashboard")).Visible = True
  Case "MasterPassword": Call UnHideAllSheets
End Select
© www.soinside.com 2019 - 2024. All rights reserved.