• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Outlook's Rules and Alerts: Run a Script

Slipstick Systems

› Outlook › Rules, Filters & Views › Outlook’s Rules and Alerts: Run a Script

Last reviewed on July 14, 2021     154 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

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.

You need to avoid processing messages using more than one rule when you are using a run a script rule. Run a script rules should be placed at the top of the rules list and include the "stop processing" action.
All actions should be in the script - don't combine actions in the rule with the run a script rule. Include all of the actions you want to take on the items that meet the rule's conditions in the VBA procedure.

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.

Script in the VBA Editor

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.

  1. 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.
    Open Rules Wizard
  2. Click New Rule.
  3. Select Apply Rule on messages I receive and click Next.
  4. Select your conditions and click Next.
  5. Select Run a script action (near the bottom).
    The finished run a script rule
  6. Click on a script.
    Select the script
  7. Select your script, click OK.
  8. Click Next then finish the rule.

For best results, all actions should be in the script.

More Information

  • Filter mail when you are not the only recipient
  • Process Mail that was Auto Forwarded by a Rule
  • Run a Script: Send Autoreply with Date
  • Filter messages containing spam or other words
  • Creating an AND rule in Outlook Rules
  • Search PDF Attachments and Forward
  • Run-a-Script Rules Missing in Outlook
  • Blocking Mail From New Top-Level Domains
  • How to Process Mail After Business Hours
  • Create Appointment From Email Automatically
  • Open Hyperlinks in an Outlook Email Message
  • Talking Reminders
  • Receive a Reminder When a Message Doesn't Arrive?
  • Delegates, Meeting Requests, and Rules
  • Run Rules Now using a Macro
  • Automatically Add a Category to Accepted Meetings
  • Save and Rename Outlook Email Attachments
  • Use a Rule to delete older messages as new ones arrive
  • Convert RTF Messages to Plain Text Format
  • Outlook AutoReplies: One Script, Many Responses
  • Use VBA to move messages with attachments
  • Save all incoming messages to the hard drive
  • Run a script rule: Reply to a message
  • Sort messages by Sender domain
  • Use a Macro to Copy Data in an Email to Excel

Additional Information:

  • How to create a script for the Rules Wizard in Outlook (MSKB)
  • Retrieving Internet Headers Using VBA in Outlook 2007/2010

Outlook's Rules and Alerts: Run a Script was last modified: July 14th, 2021 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Disable New Mail Notifications for Some Accounts
  • out of office rules
    Show a Desktop Alert when Rules move messages
  • Avoid duplicate messages caused by Outlook's Rules Wizard
  • Server-side vs. Client-side Rules

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
154 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

mishu36 (@guest_218611)
August 10, 2021 6:41 am
#218611

hi, i am trying to use "run a script" but in my "Outlook 2019", but that option is missing.

i tried to use the registry hack of "EnableUnsafeClientMailRules" but it also not working. i want to use a way around but for that i need to execute VBA Macro before outlook rules can be run. Can you please guide me on this.

here is my action plan sequence:

  1. run vba code
  2. run outlook rules
0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  mishu36
November 2, 2021 4:12 pm
#218856

Did you restart Outlook after setting the key?

If you ended the registry yourself, try using the exported key from this website.

0
0
Reply
Rakesh Kumar (@guest_217505)
January 31, 2021 12:56 am
#217505

Hello Brother,
My script is not showing in Run a Script.

2
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rakesh Kumar
February 2, 2021 12:52 am
#217515

Did you put it in ThisOutlookSession? Try putting the script in a new module instead.

The macro 'name' needs to be in this format:
Public Sub ShowMessage(Item As Outlook.MailItem)

0
0
Reply
josue aguirre (@guest_215722)
August 4, 2020 1:24 pm
#215722

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 ..."

2
0
Reply
swinn (@guest_215404)
June 11, 2020 11:44 am
#215404

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.

0
0
Reply
egenc (@guest_214960)
March 27, 2020 2:30 am
#214960

I have added script but can't see it in rule page.

rule-script.PNG
0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  egenc
June 1, 2020 11:14 pm
#215318

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)

1
-1
Reply
Isaac (@guest_215682)
Reply to  Diane Poremsky
July 29, 2020 5:45 pm
#215682

It's exactly the opposite. It MUST be in the thisoutlooksession, and CAN'T be in a regular module.

1
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Isaac
July 29, 2020 9:15 pm
#215685

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.

0
0
Reply
ardi (@guest_214476)
December 16, 2019 2:43 am
#214476

how to use in outlook 2016

0
0
Reply
Michael (@guest_214346)
November 21, 2019 3:53 pm
#214346

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.

0
0
Reply
Angelo (@guest_213566)
July 8, 2019 10:02 am
#213566

Hi,
Thank you for the article.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Remove a password from an Outlook *.pst File
  • View Shared Calendar Category Colors
  • Use PowerShell to get a list of Distribution Group members
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment