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?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,896
Messages
6,122,132
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top