vba script: add contact + distribution list

  • Thread starter Thread starter guy
  • Start date Start date
G

guy

I've set up a rule so that when a certain subject is received then a message
pops up and that email is copied to a certain folder - simple enough and no
mystery how to do that.

Now I'd like to add a bit of VBA code such that when that rule is
encountered the sender's email address is:
1. Added to the Contacts list
2. Put in a certain category
3. Added to a Distribution List

I've had a search around the VBA documentation but don't see the objects (or
recognize which objects) I need to use make this sort of thing happen. Is
there a tutorial about this sort of thing on the web?

Thanks.
 
ad 1)
For adding an item to the default contacts just call
Application.CreateItem(olContactItem).

If it isn´t the default contact list you need a reference to the folder
and then call the MapiFolder.Items.Add method. You can walk through the
hierarchie of folders (each folder has a folders collection) or use
Sue´s sample "GetFolder"
(http://www.outlookcode.com/d/code/getfolder.htm).

ad 2)
Both methods CreateItem and Items.Add returns the new object which has a
category property. This is a semicolon separated list. Just append the
new value (if need be separated by a semicolon).

ad 3)
First again you need a reference to the folder which stores the DL. With
MapiFolder.Items.Item("yourDLName") you can get a reference to the DL if
the name is unique. Otherwise you will need the EntryID or to loop
through the folder.

For the DistributionList.AddMembers method there is a good sample in the
online help of OL VBA.
 
Thanks Michael - that looks like just what I need. I will try that out
tomorrow when I have a moment on my hands. Thanks again. :)
 
Back
Top