Can I access Outlook Email contacts in VBA?

I would like to access the contact field in an email message (email settings) in Outlook. Typically, this field associates an email with a contact. Since this is a free-form text field accessible from the options dialog box, I am trying to use it to store the β€œnext step” for my email message. I would like to set the next action based on the theme, but I cannot figure out how to access this field from the outlook.mailitem object

Thanks jim

+3
source share
3 answers

I think this will answer: the field is buried in the semi-general β€œLinks” property of type olContact. To check the following code, open a new email, put something in the contacts field, and then run the code:

Sub ShowContactsField() Dim objApp As Outlook.Application Dim ActiveMailItem As Inspector Dim currLink As Link 

Set objApp = CreateObject("Outlook.Application") If TypeName(objApp.ActiveWindow) = "Inspector" Then If objApp.ActiveInspector.CurrentItem.Class = olMail Then For Each currLink In objApp.ActiveInspector.CurrentItem.Links If currLink.Type = olContact Then MsgBox currLink.Name End If Next End If End If Set objApp = Nothing End Sub

In general, I agree with Oliver; this is probably not the best place to store what you are looking for, but at least it is revealed in its native form. Check the length of the field, I think it can be limited to 255.

+1
source

Hmm, I also could not understand how to access the "Contacts" field, but from your description it looks like you are not going to use it for its intended purpose, but you just need to associate some arbitrary string of data with the email element. If this is correct, I would recommend adding fields to the UserProperties collection.

0
source

There is an easier way to get the contact list - using the Links property of the oMailItem object:

  For i = 1 To mailItem.Links.Count If mailItem.Links.item(i).Type = olContact Then Debug.Print mailItem.Links.item(i).Name End If Next i 
0
source

All Articles