Class UserProperties (Outlook VBA)

Contains UserProperty objects that represent the custom properties of an Outlook item. To use a UserProperties class variable it first needs to be instantiated, for example


Dim ups as UserProperties
Set ups = Session.CreateSharingItem.Move.Items(1).UserProperties

For Each

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


Dim upy As UserProperty
For Each upy In Session.CreateSharingItem.Move.Items(1).UserProperties
	
Next upy

Add

Creates a new user property in the UserProperties collection.

You can define custom properties by calling either the UserProperties.Add method for an Outlook item or folder, or the UserDefinedProperties.Add method for a folder. You can create a property of a type that is defined by the OlUserPropertyType enumeration, except for the following types: olEnumeration, olOutlookInternal, and olSmartFrom. To set for the first time a property created by the UserProperties.Add method, use the UserProperty.Value property instead of the SetProperties and SetProperty methods of the PropertyAccessor object. If you want to view a custom property on an item, you must use the UserProperties.Add method to create that property. Custom properties created by the PropertyAccessor are not supported in a custom view. You cannot add custom properties to Office document items such as Word, Excel, or PowerPoint files. You will receive an error when you try to programmatically add a user-defined field to a DocumentItem object.

Add (Name, Type, AddToFolderFields, DisplayFormat)


Sub AddUserProperty() 
 Dim myItem As Outlook.ContactItem 
 Dim myUserProperty As Outlook.UserProperty 
 
 Set myItem = Application.CreateItem(olContactItem) 
 Set myUserProperty = myItem.UserProperties _ 
 .Add("LastDateSpokenWith", olDateTime) 
 myItem.Display 
End Sub

Arguments

The following arguments are required:

Name (String) - The name of the property. The maximum length is 64 characters. The characters, '[', ']', '_' and '#', are not permitted in the name.

Type (OlUserPropertyType) - The type of the new property.

Here you can find possible values for OlUserPropertyType

Optional arguments

The following arguments are optional

AddToFolderFields (Boolean) - True if the property will be added as a custom field to the folder that the item is in. This field can be displayed in the folder's view. False if the property will be added as a custom field to the item but not to the folder. The default value is True.

DisplayFormat (Long) - Specifies how the property will be displayed in the Outlook user interface. This parameter can be set to a value from one of several different enumerations, determined by the OlUserPropertyType constant specified in the Type parameter. For more information on how Type and DisplayFormat interact, see DisplayFormat Property.

Class

Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for OlObjectClass.


Dim oocsClass As OlObjectClass
oocsClass = Session.CreateSharingItem.Move.Items(1).UserProperties.Class

Count

Returns a Long indicating the count of objects in the specified collection.


Dim lngCount As Long
lngCount = Session.CreateSharingItem.Move.Items(1).UserProperties.Count

Find

Locates and returns a UserProperty object for the requested property name, if it exists.

If the Custom parameter is True, only custom user properties are searched. The default value is True. To find a non-custom property such as Subject, specify the Custom parameter as False; otherwise, it returns Nothing.

Find (Name, Custom)


Dim strName As String: strName = 
Dim upyFind As UserProperty
Set upyFind = Session.CreateSharingItem.Move.Items(1).UserProperties.Find(Name:=strName)

Arguments

The following argument is required

Name (String) - The name of the requested property.

Optional arguments

The following argument is optional

Custom (Boolean) - True if custom properties on the item should be searched, False if built-in properties should be searched.

Item

Returns a UserProperty object from the collection.

Item (Index)

Index: Either the one-based index number of the object, or a value used to match the default property of an object in the collection.


Dim upy As UserProperty
Set upy = Session.CreateSharingItem.Move.Items(1).UserProperties(Index:=1)

Remove

Removes an object from the collection.

Remove (Index)

Index: The 1-based index value of the object within the collection.


Dim lngIndex As Long: lngIndex = 
Session.CreateSharingItem.Move.Items(1).UserProperties.Remove Index:=lngIndex

Session

Returns the NameSpace object for the current session.

The Session property and the GetNamespace method can be used interchangeably to obtain the NameSpace object for the current session. Both members serve the same purpose. For example, the following statements do the same function: