Checking Senders Name in Outlook VBA

Ste_Moore01

Active Member
Joined
Jul 13, 2005
Messages
467
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?
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

cpod

Board Regular
Joined
Apr 2, 2002
Messages
124
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

Active Member
Joined
Jul 13, 2005
Messages
467
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,113,847
Messages
5,544,637
Members
410,627
Latest member
georgealice
Top