Class UserProperty (Outlook VBA)
The class UserProperty represents a custom property of an Outlook item. To use a UserProperty class variable it first needs to be instantiated, for example
Dim upy as UserProperty
Set upy = Session.CreateSharingItem.Move.Items(1).UserProperties(Index:=1)
For Each
Here is an example of processing the UserProperty items in a collection.
Dim upy As UserProperty
For Each upy In Session.CreateSharingItem.Move.Items(1).UserProperties
Next upy
Class
Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for
Dim oocsClass As OlObjectClass
oocsClass = Session.CreateSharingItem.Move.Items(1).UserProperties(1).Class
Delete
Deletes an object from the collection.
Session.CreateSharingItem.Move.Items(1).UserProperties(1).Delete
Formula
Returns or sets a String representing the formula for the user property.
Sub TestFormula()
Dim tki As Outlook.TaskItem
Dim uprs As Outlook.UserProperties
Dim upr As Outlook.UserProperty
Set tki = Application.CreateItem(olTaskItem)
tki.Subject = "Work hours - Test Formula"
' TotalWork and ActualWork are in units of minutes
tki.TotalWork = 4 * 60
tki.ActualWork = 3 * 60
Set uprs = tki.UserProperties
Set upr = uprs.Add("Total&ActualWork", olFormula)
upr.Formula = "[Total Work] + [Actual Work]"
tki.Save
tki.Display
MsgBox "The Work Hours are: " & upr.Value / 60
End Sub
Name
Returns a String value that represents the display name for the object.
Dim strName As String
strName = Session.CreateSharingItem.Move.Items(1).UserProperties(1).Name
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:
Type
Returns an OlUserPropertyType constant indicating the type of the specified object. Here you can find possible values for
Dim oupType As OlUserPropertyType
oupType = Session.CreateSharingItem.Move.Items(1).UserProperties(1).Type
ValidationFormula
Returns or sets a String indicating the validation formula for the user property.
The validation formula is used by Outlook to validate the Value property when an item is saved.
Sub TestValidation()
Dim tki As Outlook.TaskItem
Dim uprs As Outlook.UserProperties
Dim upr As Outlook.UserProperty
Set tki = Application.CreateItem(olTaskItem)
tki.Subject = "Work hours"
tki.TotalWork = 3000
Set uprs = tki.UserProperties
Set upr = uprs.Add("TotalWork", olFormula)
upr.Formula = "[Total Work]"
upr.ValidationFormula = ">= 2400"
upr.ValidationText = """The WorkHours (Total Work) should be equal or greater than 5 days """
tki.Save
tki.Display
MsgBox "The Work Hours are: " & upr.Value
End Sub
ValidationText
Returns or sets a String specifying the validation text for the specified user property.
The validation text is the error message that a user receives when the Value does not meet the criteria specified in ValidationFormula.
Sub TestValidation()
Dim tki As Outlook.TaskItem
Dim uprs As Outlook.UserProperties
Dim upr As Outlook.UserProperty
Set tki = Application.CreateItem(olTaskItem)
tki.Subject = "Work hours"
' TotalWork is stored in units of minutes
tki.TotalWork = 3000
Set uprs = tki.UserProperties
Set upr = uprs.Add("TotalWork", olFormula)
upr.Formula = "[Total Work]"
upr.ValidationFormula = ">= 2400"
upr.ValidationText = """The Work Hours (TotalWork) should be equal or greater than 5 days """
tki.Save
tki.Display
MsgBox "The Work Hours are: " & upr.Value / 60
End Sub
Value
Returns or sets a Variant indicating the value for the specified custom property. Read/write.
To set for the first time a property created by the UserProperties.Add method, use the UserProperty.Value property instead of the SetProperties or SetProperty method of the PropertyAccessor object. For more information on accessing properties in Outlook, see Properties Overview.
Session.CreateSharingItem.Move.Items(1).UserProperties(1).Value =