Enumerating contacts

  • Thread starter Thread starter Thomas M.
  • Start date Start date
T

Thomas M.

Hi, I'm trying to create a VB-script that enumerates all the contacts in
Outlook, and modifies some of them. So, first I need to enumerate all the
contacts. I've been searching Google with no luck, so here's what I've come
up with:

Const olContactItem = 2

'Create Outlook Object and Contact Item
Set objOutlook = CreateObject("Outlook.application")
Set itmContact = objOutlook.CreateItem(olContactItem)

For Each myitem In mycontacts
wscript.echo myitem.FirstName & myitem.LastName & myitem.Email1Address
Next

'Clean up
Set objOutlook = Nothing
Set itmContact = Nothing

However, this doesn't work. Any help is much appreciated.

Regards,
Thomas M.
 
First of all, accessing the email address of a contact item will fire the
security prompts in secure versions of Outlook. To get around that see
http://www.slipstick.com/outlook/esecup.htm#autosec

You don't need to create a contact item but you do need to get your Contacts
folder and its Items collection.

Const olFolderContacts = 10

'Create Outlook Object
Set objOutlook = CreateObject("Outlook.application")
Set objFolder = objOutlook.Session.GetDefaultFolder(olFolderContacts)

For Each myitem In objFolder.Items
wscript.echo myitem.FirstName & myitem.LastName & myitem.Email1Address
Next

You also must be aware that a contacts folder can also hold distribution
list items as well as contact items. So you should check each item for
myitem.Class = olContact '40.
 
Back
Top