Class UserAccess (Excel VBA)

The class UserAccess represents the user access for a protected range.


To use a UserAccess class variable it first needs to be instantiated, for example

Dim usrac as UserAccess
Set usrac = ActiveSheet.Protection.AllowEditRanges(1).Users(Index:=1)

The following procedures can be used to set variables of type UserAccess: UserAccessList.Add and UserAccessList.Item.

For Each

Here is an example of processing the UserAccess items in a collection.

Dim usracUser As UserAccess
For Each usracUser In ActiveSheet.Protection.AllowEditRanges(1).Users
Next usracUser


Returns or sets a Boolean value that indicates if the user is allowed access to the specified range on a protected worksheet.

ActiveSheet.Protection.AllowEditRanges(1).Users(1).AllowEdit = True


Deletes the object.



Returns or sets a String value that represents the name of the object.

Dim strName As String
strName = ActiveSheet.Protection.AllowEditRanges(1).Users(1).Name


Adds a user access list.

Add (Name, AllowEdit)

Dim strName As String: strName = 
Dim usrac As UserAccess
Set usrac = ActiveSheet.Protection.AllowEditRanges(1).Users.Add(Name:=strName, AllowEdit:=True)


The following arguments are required:

Name (String) - The name of the user access list.

AllowEdit (Boolean) - True allows users on the access list to edit the editable ranges on a protected worksheet.


Returns a Long value that represents the number of objects in the collection.

Dim lngCount As Long
lngCount = ActiveSheet.Protection.AllowEditRanges(1).Users.Count


Removes all users who have access to a protected range on a worksheet.



Returns a single UserAccess object from the collection.

For more information about returning a single member of a collection, see Returning an object from a collection.

Item (Index)

Index: The name or index number of the object.

Dim usracItem As UserAccess
Set usracItem = ActiveSheet.Protection.AllowEditRanges(1).Users(Index:=1)