Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set a UserProperty in Outlook from VBA ?

Status
Not open for further replies.

frank42

IS-IT--Management
Mar 3, 2002
6
FR
I am trying to customize Outlook with a macro to add a UserProperty ("color") to my MailItems and set it to e.g. "red". I run the following snippet:
Code:
Dim myNameSpace As NameSpace
Dim targetFolder As MAPIFolder
Dim myItem As MailItem
Dim myProp As UserProperty

    Set myNameSpace = Application.GetNamespace("MAPI")
    Set targetFolder = myNameSpace.Folders("Personal Folders").Folders("test")
    Set myItem = targetFolder.Items(1)
    Set myProp = myItem.UserProperties.Add("Color", olText)
        myProp.Value = "red"
references to this in the rest of my macro work fine, but when the macro terminates, I cannot see the property's value in outlook. I can see that a new property has been added to my "test" folder, but item 1 does not have the value "red" and if I run another macro with :
Code:
    color = myItem.UserProperties("Color").Value
I get a "Object variable or With block variable not set" error. What am I doing wrong ?
 
I am answering my own question.

All this needed was adding
Code:
    myItem.Save
to the end of my snippet. Not obvious if this is the first time you are playing with properties in general and user properties in particular. Took me a while to find it. Hope this saves someone else some time in the future.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top