PropertyAccessor.SetProperty (Outlook)
Sets the property specified by SchemaName to the value specified by Value.
If the property does not exist and the SchemaName contains a valid property specifier, then SetProperty creates the property and assigns the value specified by Value. If the property does exist and SchemaName is valid, then SetProperty assigns the property with the value specified by Value. Note that a custom property created by using the PropertyAccessor is not supported in a custom view. If you want to view a custom property on an item, create the property by using the Add method of the UserProperties object. If the parent object of the PropertyAccessor supports an explicit Save operation, then the properties should be saved to the object with an explicit Save method call. If the object does not support an explicit Save operation, then the properties are saved to the object when SetProperties is called. Use caution and ensure that all exceptions are handled correctly. Conditions where setting properties fails include:
SetProperty (SchemaName, Value)
Sub DemoPropertyAccessorSetProperty()
Dim myProp As String
Dim myValue As Variant
Dim oMail As Outlook.MailItem
Dim oPA As Outlook.PropertyAccessor
'Get first item in the inbox
Set oMail = _
Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
'Name for custom property using the MAPI string namespace
myProp = "http://schemas.microsoft.com/mapi/string/" & _
"{FFF40745-D92F-4C11-9E14-92701F001EB3}/myCustomer"
myValue = "Dan Wilson"
'Set value with SetProperty call
'If the property does not exist, then SetProperty
'adds the property to the object when saved.
'The type of the property is the type of the element
'passed in myValue.
On Error GoTo ErrTrap
Set oPA = oMail.PropertyAccessor
oPA.SetProperty myProp, myValue
'Save the item
oMail.Save
Exit Sub
ErrTrap:
Debug.Print Err.Number, Err.Description
End Sub
Arguments
The following arguments are required:
SchemaName (String) - The name of a property whose value is to be set as specified by the Value parameter. The property is referenced by namespace. For more information, see Referencing Properties by Namespace.
Value (Variant) - The value that is to be set for the property specified by the SchemaName parameter.