?
Solved

Outlook Message Contacts

Posted on 2011-03-08
7
Medium Priority
?
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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