Protection Object [Excel 2003 VBA Language Reference]
Worksheet Protection AllowEditRanges |
Represents the various types of protection options available for a worksheet.
Using the Protection object
Use the Protection property of the Worksheet object to return a Protection object.
Once a Protection object is returned, you can use its following properties, to set or return protection options.
- AllowDeletingColumns
- AllowDeletingRows
- AllowFiltering
- AllowFormattingCells
- AllowFormattingColumns
- AllowFormattingRows
- AllowInsertingColumns
- AllowInsertingHyperlinks
- AllowInsertingRows
- AllowSorting
- AllowUsingPivotTables
The following example demonstrates how to use the AllowInsertingColumns property of the Protection object, placing three numbers in the top row and protecting the worksheet. Then this example checks to see if the protection setting for allowing the insertion of columns is False and sets it to True, if necessary. Finally, it notifies the user to insert a column.
Sub SetProtection()
Range("A1").Formula = "1"
Range("B1").Formula = "3"
Range("C1").Formula = "4"
ActiveSheet.Protect
' Check the protection setting of the worksheet and act accordingly.
If ActiveSheet.Protection.AllowInsertingColumns = False Then
ActiveSheet.Protect AllowInsertingColumns:=True
MsgBox "Insert a column between 1 and 3"
Else
MsgBox "Insert a column between 1 and 3"
End If
End Sub
Properties | AllowDeletingColumns Property | AllowDeletingRows Property | AllowEditRanges Property | AllowFiltering Property | AllowFormattingCells Property | AllowFormattingColumns Property | AllowFormattingRows Property | AllowInsertingColumns Property | AllowInsertingHyperlinks Property | AllowInsertingRows Property | AllowSorting Property | AllowUsingPivotTables Property
Parent Objects | Worksheet Object
Child Objects | AllowEditRanges Object