Solved

Outlook Message Contacts

Posted on 2011-03-08
7
370 Views
Last Modified: 2012-05-11
Hi,

I would like to create a script that will allow me to set the "Contacts" property in an Outlook message to a specific text string.

Please note I am not looking to work with Outlook Contacts in any way, I am taking about the field labelled "Contacts..." if you choose message properties (options in pre-2010 versions) of an e-mail message.

Thanks,
Kevin
0
Comment
Question by:kevinmcallister
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 35069810
Hi, Kevin.

The Contacts property is intended to be a link to a contact item.  What is that you want to put in the field and will it be the same string for every message?  If not, then how should the script determine what to enter in the field?
0
 

Author Comment

by:kevinmcallister
ID: 35070543
It would be the same for every message, yes. I know that if I do this by hand, I can type in the contact name and it accepts what I have typed in.

Thanks in advance for any help you can offer.

Kevin
0
 
LVL 76

Expert Comment

by:David Lee
ID: 35071139
Something like this will do it.  This would add a link to a contact with the name of John Doe to all outbound emails.

Follow these instructions to add the code to Outlook 2007 (I don't have a set of instructions for 2010 yet).

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkLink As Outlook.Link, olkCon As Outlook.ContactItem
    If Item.Class = olMail Then
        'On the next line change the full name of the contact to link to'
        Set olkCon = Session.GetDefaultFolder(olFolderContacts).Items.Find("[FullName] = 'John Doe'")
        If TypeName(olkCon) <> "Nothing" Then Set olkLink = Item.Links.Add(olkCon)
        Item.Save
    End If
End Sub

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kevinmcallister
ID: 35074492
This is great! Thanks.

Sorry to be a pain, but can you advise if this would work for a message I have already received which has a contact in it, but which I want to change to, say, John Doe?

Thanks again so much for your help!
Kevin
0
 
LVL 76

Expert Comment

by:David Lee
ID: 35074785
You're welcome!

No pain.  This script only works for messages that are being sent.  I've created another script (below) that's a knock-off of the first script and will work for message in any Outlook folder.  Simply add this code to what you already have.  To use it

1.  Select one or more messages in any folder.
2.  Run the macro.
Sub SetMessageContact()
    Dim olkMsg As Object, olkLink As Outlook.Link, olkCon As Outlook.ContactItem
    'On the next line change the full name of the contact to link to'
    Set olkCon = Session.GetDefaultFolder(olFolderContacts).Items.Find("[FullName] = 'John Doe'")
    For Each olkMsg in Application.ActiveExplorer.Selection
        If olkMsg.Class = olMail Then
            If TypeName(olkCon) <> "Nothing" Then Set olkLink = olkMsg.Links.Add(olkCon)
            Item.Save
        End If
    Next
    Set olkMsg = Nothing
    Set olkLink = Nothing
    Set olkCon = Nothing
End Sub

Open in new window

0
 

Author Comment

by:kevinmcallister
ID: 35081304
Thanks so much. I feel really guilty about this, but it's giving me an error on the line

Item.Save

Any ideas? I have spent most of the morning poking round fora online trying to see if I could resolve it myself, but I'm getting nowhere!

Thanks again.
Kevin
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 35081443
That's my fault.  Because of the way this routine needs to work I changed a variable name and missed changing that one occurrence.  Line 8 should read

    olkMsg.Save
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now