Class Protection (Excel VBA)

The class Protection represents the various types of protection options available for a worksheet.


The following procedures in this class have been grouped together and are described on a separate theme page

Allow with its procedures AllowDeletingColumns, AllowDeletingRows, AllowEditRanges, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowSorting and AllowUsingPivotTables


AllowFiltering returns True if the user is allowed to make use of an AutoFilter that was created before the sheet was protected.

Sub ProtectionOptions() 
 ' Unlock row 1. 
 Rows("1:1").Locked = False 
 ' Allow row 1 to be filtered on a protected worksheet. 
 If ActiveSheet.Protection.AllowFiltering = False Then 
 ActiveSheet.Protect AllowFiltering:=True 
 End If 
 MsgBox "Row 1 can be filtered on this protected worksheet." 
End Sub

AllowInsertingHyperlinks returns True if the insertion of hyperlinks is allowed on a protected worksheet.

Sub ProtectionOptions() 
 ' Unlock cell A1. 
 Range("A1").Locked = False 
 ' Allow hyperlinks to be inserted on a protected worksheet. 
 If ActiveSheet.Protection.AllowInsertingHyperlinks = False Then 
 ActiveSheet.Protect AllowInsertingHyperlinks:=True 
 End If 
 MsgBox "Hyperlinks can be inserted on this protected worksheet." 
End Sub