Microsoft Office Tutorials and References
In Depth Information
18.3.2 The AllowEditRange Object
For example, if the AllowSorting property is True , then users can still sort unlocked cells in a
protected worksheet.
The AllowEditRanges property returns an AllowEditRanges object, discussed separately in the
text.
18.3.2 The AllowEditRange Object
The AllowEditRange object allows a specified range of cells on a worksheet to be password
protected from editing. Once a range has been protected in this way, and the entire worksheet has
been protected , any attempt at editing cells in that range will require the password.
Here is some code that assigns a password to a range on the active worksheet. It also demonstrates
the use of the AllowEditRanges collection.
Sub ProtectRange()
Dim ws As Worksheet
Dim i As Integer
Set ws = Application.ActiveSheet
' Remove protection
ws.Unprotect
' Delete all current protection ranges
'MsgBox ws.Protection.AllowEditRanges.Count
For i = 1 To ws.Protection.AllowEditRanges.Count
Debug.Print ws.Protection.AllowEditRanges(i).Title
ws.Protection.AllowEditRanges(i).Delete
Next
' Add a protection range
ws.Protection.AllowEditRanges.Add _
Title:="Headings", _
Range:=Range("A1:A4"), _
Password:="hide"
' Protect sheet (else protection range is not enabled)
ws.Protect
End Sub
The properties of the AllowEditRange object are:
Range
Returns or sets the range associated with the AllowEditRange object.
Title
Returns or sets the title (i.e. name) of the range associated with the AllowEditRange
object.
Users
Returns the collection of UserAccessObjects associated with the AllowEditRange object.
For more on this, see the section on the UserAccess object.
Search JabSto ::




Custom Search