# Checking Senders Name in Outlook VBA



## Ste_Moore01 (Oct 24, 2006)

Hi everybody,

I'm trying to make a macro in Outlook that checks new mail for the senders email address and if it is a certain address then it runs a macro.

The problem is, I can't figure out how to do it!

I know this site is mainly Excel based but I know some of you may know how.  If no-one does, does anyone know of any other sites which may be able to help me?


----------



## cpod (Oct 25, 2006)

First write the macro something like:

Public Sub test(olNew As MailItem)
MsgBox "New email" & olNew.SenderName
End Sub

You must include the "olNew As MailItem" so that Outlook can pass you email even if you don't reference it, otherwise the macro will not run.

Then you add an Outlook rule that looks for the email address, and in the "what to do with with email" window select "run script" and choose your macro.


----------



## Ste_Moore01 (Nov 3, 2006)

Hi cpod!

Thanks for thr reply.  I've used you code and it appears to work well but it brings up a message saying "A program is trying to access e-mail address you have stored in Outlook. Do you want to allow this?"

I know you have to click Yes but is there a way that I can remove this message from being displayed when this specific code is run?


----------



## cpod (Nov 6, 2006)

There is a freeware program that seems to solve this problem:

http://www.contextmagic.com/express-clickyes/

It's worked well for me.


----------



## Ste_Moore01 (Nov 9, 2006)

Thanks again cpod.

Not a perfect program but it helps me out a lot.

Thanks!


----------

