Class UserAccess (Excel VBA)
The class UserAccess represents the user access for a protected range.
Set
To use a UserAccess class variable it first needs to be instantiated, for example
Dim strName As String: strName =
Dim ual As UserAccessList: Set ual =
Dim usrac As UserAccess
Set usrac = ual.Add(Name:=strName, AllowEdit:=True)
The following procedures can be used to set variables of type UserAccess: UserAccessList.Item, UserAccessList.Add and AllowEditRange.Users
For Each
Here is an example of processing the UserAccess items in a collection.
Dim aer As AllowEditRange: Set aer =
Dim usracUser As UserAccess
For Each usracUser In aer.Users
Next usracUser
AllowEdit
Returns or sets a Boolean value that indicates if the user is allowed access to the specified range on a protected worksheet.
Delete
Deletes the object.
Name
Returns or sets a String value that represents the name of the object.
UserAccessList.Add
Adds a user access list.
Syntax : expression.Add (Name, AllowEdit)
Arguments
UserAccessList.Count
Returns a Long value that represents the number of objects in the collection.
UserAccessList.DeleteAll
Removes all users who have access to a protected range on a worksheet.
Sub UseDeleteAll()
Dim wksSheet As Worksheet
Set wksSheet = Application.ActiveSheet
' Remove all users with access to the first protected range.
wksSheet.Protection.AllowEditRanges(1).Users.DeleteAll
End Sub
UserAccessList.Item
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.
Syntax : expression.Item (Index)
Index: The name or index number of the object.