• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • 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     155 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

Related Posts:

  • Disable New Mail Notifications for Some Accounts
  • out of office rules
    Show a Desktop Alert when Rules move messages
  • A simple run a rule script marks Outlook messages read when the messag
    Use a run a script rule to mark messages read
  • Creating an AND rule in Outlook 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
155 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Mario
July 31, 2023 10:33 am

Hello Diane, greetings from Brazil!

We have a doubt in outlook and needs your help:

In my company , we need automate some tasks in Outlook. For example, when we apply some tag in email, we want these email tagged be moved to folder automatically.

I know that outlook web and outlook desktop have rules that i can automate many tasks, like move email to folder from tag, sender, subject, etc, that rules works when emails are sended and received.

I found these manual task in Outlook desktop that move email to folder after i tagged that email manually. In these task, we need click on button "Run Rules Now" manually:

https://filestore.community.support.microsoft.com/api/images/d58b5400-c18c-426d-84fa-0a934716c28e?upload=true

https://filestore.community.support.microsoft.com/api/images/b7a0c5d8-e7e9-41f6-a131-b074cd359483?upload=true

however, in my company we need automate tasks after email arrive in inbox.

This is my doubt: is possible create automatic task for when i apply tag in email received, these email be move to folder automatically? there are script or macro related?

Thanks a lot!!

Mario

0
0
Reply
mishu36
August 10, 2021 6:41 am

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
Author
Reply to  mishu36
November 2, 2021 4:12 pm

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
January 31, 2021 12:56 am

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

2
0
Reply
Diane Poremsky
Author
Reply to  Rakesh Kumar
February 2, 2021 12:52 am

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
August 4, 2020 1:24 pm

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
June 11, 2020 11:44 am

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
March 27, 2020 2:30 am

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

rule-script.PNG
0
0
Reply
Diane Poremsky
Author
Reply to  egenc
June 1, 2020 11:14 pm

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
Reply to  Diane Poremsky
July 29, 2020 5:45 pm

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

1
0
Reply
Diane Poremsky
Author
Reply to  Isaac
July 29, 2020 9:15 pm

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
December 16, 2019 2:43 am

how to use in outlook 2016

0
0
Reply
Michael
November 21, 2019 3:53 pm

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

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

Latest EMO: Vol. 30 Issue 31

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

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

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

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.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

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

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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 | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

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

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
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