[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Outlook Message Contacts

Posted on 2011-03-08
7
Medium Priority
?
379 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
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 …

656 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