Solved

Outlook Message Contacts

Posted on 2011-03-08
7
372 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

777 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