【问题标题】:Protect Excel Worksheet with multiple protection variables使用多个保护变量保护 Excel 工作表
【发布时间】:2016-11-05 17:13:52
【问题描述】:

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

我已经走到这一步了:

Worksheets("Sheet 1").Protect Password:="Password"

接下来我要写什么以允许用户: 选择未锁定的单元格 格式化列/行 种类 使用自动过滤器

谢谢,

【问题讨论】:

  • 我猜是取消保护

标签: excel vba password-protection


【解决方案1】:

有 16 个参数可用于工作表的 Protect 方法。这是基于这篇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

【讨论】:

    【解决方案2】:

    只是为了补充@Robin给出的答案,这是.Protect函数的URL,您可能会发现阅读每个参数的作用很有用,有些被假定为真,有些被假定为假.

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

    亲切的问候,

    刘易斯格鲁法洛

    【讨论】:

    • 谢谢刘易斯!罗宾已经提到过这个链接;但是在你提到它之后,我又看了一眼,发现了更多有用的信息,我将使用它。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 2019-05-27
    相关资源
    最近更新 更多