我们有一些以当前格式工作的 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
将
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