Class Protection (Excel VBA)

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

Themes

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

Properties

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

Sub ProtectionOptions() 
 
 ActiveSheet.Unprotect 
 
 ' 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() 
 
 ActiveSheet.Unprotect 
 
 ' 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