访问用户锁定的Excel文档中的多个页面

时间:2015-06-10 15:47:34

标签: excel excel-vba vba

我正在尝试创建一个预算文档,其中每个部门只能访问他们的特定页面 - 我有一部分工作 - 我无法让ADMIN访问所有页面。 这就是我到目前为止我的UserForm的代码:(我希望“Scott”能够打开所有页面而不仅仅是“概述”)

Dim bOK2Use As Boolean

Private Sub btnOK_Click()
Dim bError As Boolean
Dim sSName As String
Dim ws As Worksheet
Dim p As DocumentProperty
Dim bSetIt As Boolean

bOK2Use = False
bError = True
If Len(txtUser.Text) > 0 And Len(txtPass.Text) > 0 Then
    bError = False
    Select Case txtUser.Text
        Case "Scott"
            sSName = "Overview"
            If txtPass.Text <> "act2" Then bError = True
        Case "Chris"
            sSName = "Run Crew"
            If txtPass.Text <> "act2" Then bError = True
        Case Else
            bError = True
    End Select
End If
If bError Then
    MsgBox "Invalid User Name or Password"
Else
    'Set document property
    bSetIt = False
    For Each p In ActiveWorkbook.CustomDocumentProperties
        If p.Name = "auth" Then
            p.Value = sSName
            bSetIt = True
            Exit For
        End If
    Next p
    If Not bSetIt Then
        ActiveWorkbook.CustomDocumentProperties.Add _
          Name:="auth", LinkToContent:=False, _
          Type:=msoPropertyTypeString, Value:=sSName
    End If


    bOK2Use = True
    Unload UserForm1
End If
End Sub

Private Sub UserForm_Terminate()
If Not bOK2Use Then
    ActiveWorkbook.Close (False)
End If
End Sub

谢谢!

0 个答案:

没有答案