Protection Members

Use the Worksheet objects Protection method to get a reference to the Protection object. The Protection object has the following members:

AllowDeletingColumns

AllowDeletingRows

AllowEditRanges

AllowFiltering

AllowFormattingCells

AllowFormattingColumns

AllowFormattingRows

AllowInsertingColumns

AllowInsertingHyperlinks

AllowInsertingRows

AllowSorting

AllowUsingPivotTables

The Protection object provides a set of read-only properties that describe the types of protection in effect on a worksheet. These settings correspond to the settings in the Protect Sheet dialog box and to the arguments used in the Worksheet object’s Protect method. For example, the following code displays a report on the Protection property settings in the Immediate window:

    Set ws = ThisWorkbook.Sheets("Protection")
    Set prot = ws.Protection
    Debug.Print "Can delete:", "Columns?", "Rows?"
    Debug.Print , prot.AllowDeletingColumns, prot.AllowDeletingRows
    Debug.Print "Can:", "Filter?", "Sort?", "Use Pivot Tables?"
    Debug.Print , prot.AllowFiltering, prot.AllowSorting, prot.AllowUsingPivotTables
    Debug.Print "Can format:", "Cells?", "Columns?", "Rows?"
    Debug.Print , prot.AllowFormattingCells, prot.AllowFormattingColumns, _
      prot.AllowFormattingRows
    Debug.Print "Can insert:", "Columns?", "Rows?", "Hyperlinks?"
    Debug.Print , prot.AllowInsertingColumns, prot.AllowInsertingRows, _
      prot.AllowInsertingHyperlinks

You also use the Protection object to get a reference to the AllowEditRanges ...

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.