Using the "Rules and Alerts" option to "run a script", the list of scripts to run is empty. What makes a script appear in the list?
The argument must by type MailItem or MeetingItem for the subroutine to be available in the Rules Wizard in Outlook 2007. In Outlook 2010 and 2013 (and up), PostItem also works.
Something like this:
Public Sub ShowMessage(Item As Outlook.MailItem) 'code End Sub
Using VBA Editor
Open Outlook's VBA editor by pressing Alt+F11 and expand Microsoft Office Outlook Objects then double click on ThisOutlookSession.
You'll type or paste the code into the module, then create the rule with the 'run script' Action and select this script
Create a Run a Script Rule
After the script is written, you need to add it to a rule.
If you have Outlook 2016 and run a script action is missing, see "Run-a-Script Rules Missing in Outlook" for the fix.
- Open Rules Wizard. In Outlook 2010 and 2013, it's on Outlook's Home ribbon,
Rules > Manage Rules & Alerts. Look on the Tools menu in older versions.
- Click New Rule.
- Select Apply Rule on messages I receive and click Next.
- Select your conditions and click Next.
- Select Run a script action (near the bottom).
- Click on a script.
- Select your script, click OK.
- Click Next then finish the rule.
For best results, all actions should be in the script.
More Information
More Run a Script Samples:
- Autoaccept a Meeting Request using Rules
- Automatically Add a Category to Accepted Meetings
- Blocking Mail From New Top-Level Domains
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Create a Task from an Email using a Rule
- Create an Outlook Appointment from a Message
- Create Appointment From Email Automatically
- Delegates, Meeting Requests, and Rules
- Delete attachments from messages
- Forward meeting details to another address
- How to Change the Font used for Outlook's RSS Feeds
- How to Process Mail After Business Hours
- Keep Canceled Meetings on Outlook's Calendar
- Macro to Print Outlook email attachments as they arrive
- Move messages CC'd to an address
- Open All Hyperlinks in an Outlook Email Message
- Outlook AutoReplies: One Script, Many Responses
- Outlook's Rules and Alerts: Run a Script
- Process messages received on a day of the week
- Read Outlook Messages using Plain Text
- Receive a Reminder When a Message Doesn't Arrive?
- Run a script rule: Autoreply using a template
- Run a script rule: Reply to a message
- Run a Script Rule: Send a New Message when a Message Arrives
- Run Rules Now using a Macro
- Run-a-Script Rules Missing in Outlook
- Save all incoming messages to the hard drive
- Save and Rename Outlook Email Attachments
- Save Attachments to the Hard Drive
- Save Outlook Email as a PDF
- Sort messages by Sender domain
- Talking Reminders
- To create a rule with wildcards
- Use a Macro to Copy Data in an Email to Excel
- Use a Rule to delete older messages as new ones arrive
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments
Additional Information:
- How to process incoming messages in Microsoft Outlook (Outlookcode.com)
- How to create a script for the Rules Wizard in Outlook (MSKB)
- Retrieving Internet Headers Using VBA in Outlook 2007/2010
Hello, can you please help me with a problem?
I have a rule in Outlook that runs a script, but it suddenly doesn't work anymore. And when I want to change this rule or create a new one I get a message:
"This rule will only be executed when you check your email ..."
Discovered the hard way that if the Sub you are trying to invoke with an Outlook Rule has an Optional parameter, the Rule Editor won't display it for you to select.
I have added script but can't see it in rule page.
The script needs to be named in this format, preferably in a module (not thisoutlooksession) - you don't need to call the mail object Item, but you do need it in the ().
Public Sub ShowMessage(Item As Outlook.MailItem)
It's exactly the opposite. It MUST be in the thisoutlooksession, and CAN'T be in a regular module.
No, it will work in either, but it is recommended to put it in a module. I've had instances where it was not 'seen' if in thisoutlooksession, but none where it was not seen in a module.
how to use in outlook 2016
I'm trying to use the "Send a message to someone when a reminder fires" macro from this page: https://www.slipstick.com/developer/send-email-outlook-reminders-fires/, but it seems like the parameters of that code aren't compatible with what's required for the Rules Wizard to recognize it as a script.
Hi,
Thank you for the article.
Hi,
I have tried with the options as suggested, but while i tried to set the rules in the action pane the rule "Run a Script", I cant able to find my macro name while i clicked on the script underlined one. Could you pls suggest me why can't able to find the macro name. Please?
Thanks,
Yuvaraj
What is the macro name? It needs to be formatted like this
Public Sub ShowMessage(Item As Outlook.MailItem)
Is the macro in thisoutlooksession or a module? It should be visible in either, but sometimes won't work in thisoutlooksession.
how to give a name like this? From where
I have set up a forward script on a co-workers computer, it worked for about 4 days and then it quit working. when I investigated the script was gone. the next week it did the same thing. I have the exact same script and rule set up on my computer and have never had this issue.