tags:

views:

194

answers:

2

I am trying to make a macro in Outlook that will scan the To: list for a certain text string, and spit out a message if all but one (or two, etc) addresses have it. Is there a simple way to do this?

Essentially, I am trying to write something that'll avoid being able to send a restricted message to a bunch of people with the string 'xyz' in the address, if one or more do not have it. AutoComplete makes this difficult, without checking through one-by-one.

+2  A: 

This is possible using Outlook VBA.

You'd have to write an event hook for when the user sends an email. This is done using the Application_ItemSend(ByVal Item As Object, Cancel As Boolean) where Item is the item being sent (email or appointment), and cancel is a boolean you can set to stop the email from being sent.

In your code you would want to look at the recipients collection on the Item object to see who is going to be receiving the email. For example:

Dim CurrRecip As Recipient
For Each CurrRecip in Item.Recipients
    If InStr(1, CurrRecip.Address , "your search text here" , vbCompareText ) Then
        debug.print "Message here..."
    End If
Next CurrRecip

Hopefully that helps...

Jon Fournier
A: 

hey, Jons post worked out really well. Thanks for that.

But there is one backdraw: When recipients are added using the outlook contact folder I do not receive the "normal" email-address.

Is there a solution for that? I tried other properties of CurrRecip without success and was not able to figure out an alternative solution.

thanks max

max