保护 Excel 具有多个保护变量的工作表

Protect Excel Worksheet with multiple protection variables

使用 Excel VBA,如何锁定具有多个不同变量的工作表,即允许用户使用自动筛选器和排序选项。

我已经走到这一步了:

工作表("Sheet 1").保护密码:="Password"

我接下来要写什么以允许用户: Select un/locked 个单元格 格式 columns/rows 种类 使用自动过滤器

谢谢,

工作表的 Protect 方法可以使用 16 个参数。这是基于这篇 MSDN 文章的代码示例:

Option Explicit

Sub LockSheet()

    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets(1)

    ws.Protect Password:="Foo", _
        DrawingObjects:=True, _
        Contents:=True, _
        Scenarios:=True, _
        UserInterfaceOnly:=True, _
        AllowFormattingCells:=True, _
        AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, _
        AllowInsertingColumns:=True, _
        AllowInsertingRows:=True, _
        AllowInsertingHyperlinks:=True, _
        AllowDeletingColumns:=True, _
        AllowDeletingRows:=True, _
        AllowSorting:=True, _
        AllowFiltering:=True, _
        AllowUsingPivotTables:=True

End Sub

只是添加到@Robin 给出的答案中,这里是 .Protect 函数的 URL,您可能会发现阅读每个参数的作用很有用,还有一些被假定为是的,有些是假的。

https://msdn.microsoft.com/en-us/library/office/ff840611.aspx

亲切的问候,

刘易斯咕噜牛