阻止用户查看Excel工作表

时间:2015-04-16 14:49:43

标签: excel vba excel-vba

我正在编写一个宏,在主菜单中有一个按钮可以访问“管理”工作表,可以在其中进行重要更改。我只希望某些用户访问此管理工作表,我想知道是否有办法密码保护查看工作表,而不仅仅是修改它。

1 个答案:

答案 0 :(得分:3)

你可以这样做:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Update 20140925
Dim xSheetName As String
xSheetName = "Sheet1"
If Application.ActiveSheet.Name = xSheetName Then
    Application.EnableEvents = False
    Application.ActiveSheet.Visible = False
    xTitleId = "KutoolsforExcel"
    response = Application.InputBox("Password", xTitleId, "", Type:=2)
    If response = "123456" Then
        Application.Sheets(xSheetName).Visible = True
        Application.Sheets(xSheetName).Select
    End If
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End Sub

这实际上会创建一个受密码保护的工作表,只有在提供的密码正确时才能看到该工作表。 这个答案来自http://www.extendoffice.com/documents/excel/2134-excel-password-protect-hidden-sheet.html#a1