Avatar of Rob Rudloff
Rob RudloffFlag for United States of America asked on

Use VBA / macro to modify a rule in Outlook ?

Hi.  I am a developer, but not familiar with the Outlook 2013 Object Model.
I have a client that has a small task -- In Outlook, he would like to be able to select an email message in his Inbox, and then click a button to append the sender's address to an existing "move to" rule.

He has a "customers.pst" file;  In that PST file, there is a "New Mail" folder.

In Outlook, he already has a rule defined that moves new emails from a list of senders (by email address)  from his default Inbox to the "Customers\New Mail" folder  (when new email is received.)   It takes many steps to manually add a new customer address to that rule.

I assume this would be a simple VBA macro, wherein I would get the "sender" from a selected message, then add it to the existing rule using a call to "Outlook.Rule.Conditions.From.Recipients.Add" or something like that.

I did find this article:  Create a Rule to Move Specific E-mails to a Folder  but have not been successful in modifying the sample code to meet my needs -- I've made a few attempts, but have not been able to point to the proper PST\Folder or successfully modify the "conditions".  

It seems like it would not take much code, so does anyone have any examples?

-- Thanks
Microsoft DevelopmentOutlookMicrosoft Office

Avatar of undefined
Last Comment
Rgonzo1971

8/22/2022 - Mon
SOLUTION
Rgonzo1971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015

It seems like it would not take much code, so does anyone have any examples?
What about no code?

It I were setting this up I would keep it simple. I would create a rule that uses "Sender in specified address book"

Create a separate "customer" address book for all customers that need to be moved to the "Customers\New Mail" folder.

To update the rule all you have to do is add someone to the "customer" address book.

Ouitlook Rule
ASKER
Rob Rudloff

rgonzo1971 --
Yes, that is a good example, and similar to the one in my link.  My problem is that they "create" a new rule:
'Create the rule by adding a Receive Rule to Rules collection
 Set oRule = colRules.Create("Dan's rule", olRuleReceive)
I need to figure out how to iterate through existing rules to find the existing rule "Move To Customers"

-- thanks
ASKER CERTIFIED SOLUTION
Rgonzo1971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy