• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Run a Script Rule: Forwarding Messages

Slipstick Systems

› Outlook › Rules, Filters & Views › Run a Script Rule: Forwarding Messages

Last reviewed on April 7, 2025     330 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.

A visitor to our Outlook Forums wanted to know how to change a subject and forward a message using rules:

I want to create a rule that I can run on a folder containing a number of messages that forwards each message to a new email address (a dropbox for a database). I need to write my own subject line, so that the database will read the subject line and then know to parse the document and extract the required information.

You can do this using either VBA or a Run a Script rule. If you using a rule to move the messages to another folder, the run a script rule is probably the best and can easily forward mail meeting specific conditions. You can run the rule as messages arrive or run it on the messages in the folder at any time using Run Rules Now.

Outlook 2003 users will receive the dreaded "something is trying to access your address book. Allow?" message. To avoid this, install ClickYes or Mapilab's Advanced Security software. Both are free. Mapilab's product will bypass the dialog (after you OK it the very first time), while ClickYes does the clicking for you.

Run a Script Rule

Press Alt+F11 to open the VB Editor and paste the following code into ThisOutlookSession. Create the rule in Outlook and select the script.

Change subject and forward rule

Don't forget to change the subject and email address!

Sub ChangeSubjectForward(Item As Outlook.MailItem)
    Item.Subject = "Test"
 Item.Save
 
Set myForward = Item.Forward
myForward.Recipients.Add "alias@domain.com"

myForward.Send

End Sub

To Delete the Sent Copy of the Message

To delete (or not save) the sent copy after it is forwarded, use myForward.DeleteAfterSubmit = True before the Send command.

Sub ChangeSubjectForward(Item As Outlook.MailItem)

Set myForward = Item.Forward
myForward.Recipients.Add "alias@domain.com"

' To BCC an address or DL, try this:
'myForward.BCC = "alias"

myForward.DeleteAfterSubmit = True

myForward.Send

End Sub

 

Find a code in the message body, then forward

This example combines the first script above with the macro at Use RegEx to extract text from an Outlook email message to look for a tracking code in the message body, then forward the message and include the code in the message subject.

Sub CodeSubjectForward(Item As Outlook.MailItem)

' Set reference to VB Script library
' Microsoft VBScript Regular Expressions 5.5

    Dim M1 As MatchCollection
    Dim M As Match
    
    Set Reg1 = New RegExp
        
    With Reg1
        .Pattern = "(Tracking Code\s*(\w*)\s*)"
        .Global = True
    End With
    If Reg1.Test(Item.Body) Then
    
        Set M1 = Reg1.Execute(Item.Body)
        For Each M In M1
        
'allows for multiple matches in the message body
        Item.Subject = M.SubMatches(1) & "; " & Item.Subject
        
        Next
    End If

 Item.Save
  
Set myForward = Item.Forward
myForward.Recipients.Add "alias@domain.com"
 
myForward.Send
 
End Sub

 

Forward Attachment & Change Subject

This version of the run a script macro gets the attachment name and puts it in the subject field. If there are multiple attachments, it exits the macro after the first matching attachment (and Excel file in this sample).

Sub ChangeSubjectForwardAttachment(Item As Outlook.MailItem)
Dim oAtt As Attachment
strAtt = ""
For Each oAtt In Item.Attachments
Debug.Print oAtt.FileName

' check extension
If Right(oAtt.FileName, 5) = ".pdf" Then

' check filename
'If InStr(oAtt.FileName, "keyword") > 0 Then

  Set myforward = Item.Forward
   myforward.Recipients.Add "alias@domain.com"
   myforward.Subject = oAtt.FileName
   myforward.Display 'Send
   Exit Sub

End If
Next oAtt

End Sub

 

Forward from another account

This script will forward the message from a different email account. As written, it will send from the second account in the Account list in File > Account Settings > Account Settings, under Email accounts. Change the number as needed.

myForward.SendUsingAccount = olNS.Accounts.Item(2)

check account order
Sub ChangeAccountForward(Item As Outlook.MailItem)
Dim olNS As Outlook.NameSpace
Set olNS = Application.GetNamespace("MAPI")

Set myForward = Item.Forward

myForward.Recipients.Add "alias@domain.com"
myForward.SendUsingAccount = olNS.Accounts.Item(2)
 
myForward.Send

Set olNS = Nothing
End Sub

 

"Change subject then forward" VBA Macro version

If you prefer a macro you can run on all messages in a folder at any time, use this code sample. This macro was put together using the script above and the code sample at Add a file number or keyword to the subject line of messages.

To use, paste into ThisOutlookSession and run, or add to a toolbar, ribbon, or QAT button.

Don't forget to change the subject and email address.

Sub ChangeSubjectThenSend()
Dim myolApp As Outlook.Application
Dim aItem As Object

Set myolApp = CreateObject("Outlook.Application")
Set mail = myolApp.ActiveExplorer.CurrentFolder

For Each aItem In mail.Items
      aItem.Subject = "New Subject"
    aItem.Save
    
    Set myForward = aItem.Forward
    myForward.Recipients.Add "alias@domain.com"
    myForward.Send

Next aItem
End Sub

Forward messages in a quarantine mailbox

This macro forwards messages that were sent to a quarantine folder by antispam software back to the original recipient. The original subject is restored.

To use, add the macro to the ribbon or toolbar. Select the message and click the button.

Use myForward.Send to automatically send the message.

You need to set a reference to the VB Script library:
Microsoft VBScript Regular Expressions 5.5 in the VB Editor's Tools, References menu.

Sub ChangeSubjectThenForward()
Dim oItem As Outlook.MailItem
Dim strSendto, strSubject As String
Dim myForward As MailItem
  
' Set reference to VB Script library
' Microsoft VBScript Regular Expressions 5.5
    Dim Reg1 As RegExp
    Dim M1 As MatchCollection
    Dim Reg2 As RegExp
    Dim M2 As MatchCollection
    Dim M As Match
 
Set oItem = ActiveExplorer.Selection.Item(1)
Set myForward = ActiveExplorer.Selection.Item(1).Forward

 ' regex from http://slipstick.me/2k3zf
 ' check the original, not the forward
    Set Reg1 = New RegExp
    With Reg1
        .Pattern = "(To[:](.*))"
        .Global = True
    End With
    If Reg1.test(oItem.Body) Then
     
        Set M1 = Reg1.Execute(oItem.Body)
        For Each M In M1
           strSendto = M.SubMatches(1)
        Next
    End If
    
    Set Reg2 = New RegExp
    With Reg2
        .Pattern = "(Subject[:](.*))"
        .Global = True
    End With
    If Reg2.test(oItem.Body) Then
     
        Set M2 = Reg2.Execute(oItem.Body)
        For Each M In M2
           strSubject = M.SubMatches(1)
        Next
    End If

    myForward.Recipients.Add strSendto
    myForward.Subject = strSubject
    myForward.Display ' change to .send to automatically send 

End Sub

 

Add the sender name to a read receipt

Michal wanted to add the sender's name to a read receipt subject. Because it's a Report item and not a Message, you need to tweak the script a bit. The Reports also don't have a sender name, but you can use Regular Expressions (regex) to grab the name from the message body.

Unlike the scripts above, this script is using late-binding with the regex library. This makes the macro more portable, as you don't need to set the reference to the Regex library. If you are using multiple macros with regex, it's generally better to use early binding.

The Rule condition will be "uses the Report form" (choose Reports from Application Forms in the dialog). Note: if run script is not an option in Actions, see "Run-a-Script Rules Missing in Outlook".

read reciept report rule
Sub AddSender(Item As Outlook.ReportItem)
 
Dim Reg1 As Object 'RegExp
Dim Matches As Object 'MatchCollection
Dim Match As Object 'Match
Dim strSender As String

Set Reg1 = CreateObject("VBScript.RegExp")

Reg1.Pattern = "To[:]\s*((.*))\r"

Set Matches = Reg1.Execute(Item.Body)

For Each Match In Matches
  strSender = Match.SubMatches(1)
Next

 Item.Subject = Item.Subject & " - " &  strSender
 Item.Save
    
End Sub

 

Testing Run a Script Macros

Testing run a script macros tends to be a PITA, since they only run when new messages arrive or when you run the rule manually. Sending new messages takes time and using Run Rules Now with a bad script or the wrong conditions can really screw up your day.

Tip: If you need to test the rule conditions, you can't avoid using Run Rules Now but you can minimize risk if you copy messages to a new folder and run it on messages in that folder.

When you just need to test the script, you can use a simple "stub" macro that calls the script, running it on the selected message.

Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
 

Tools

ClickYes Pro

ClickYes Pro is a tuning tool for Microsoft Outlook security settings. It allows you to configure which applications can automatically send emails using Outlook and access email addresses stored in Outlook address book. ClickYes Pro runs as a background task providing a convenient icon in the taskbar notification area to manage allowed applications. It uses an encrypted storage and is highly secure and safe. Client and Server versions available. Works with Outlook 2000 - Outlook 2010.

Outlook Security Manager

Developers can use this to avoid the security prompts in Outlook.

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

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

Run a Script Rule: Forwarding Messages was last modified: April 7th, 2025 by Diane Poremsky

Related Posts:

  • A simple run a rule script marks Outlook messages read when the messag
    Use a run a script rule to mark messages read
  • Run a script rule: Autoreply using a template
  • Run a script rule: Reply to a message
  • Send a New Message when a Message Arrives

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
330 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Antony joseph
November 16, 2023 3:21 am

Hi, I would like to get a message "Mail not sent" if I have recipients of domain x and domain y i.e. tony@x.com; tony@y.com. This would be a safety measure to ensure I do not mistakenly send an email to both companies. Any help scripting this out woud be appreciated

0
0
Reply
Scott Van Heurck
September 19, 2023 10:38 pm

Not sure I should be messing with VBA - is it inbuilt now?

0
0
Reply
Diane Poremsky
Author
Reply to  Scott Van Heurck
September 20, 2023 10:04 pm

VBA and run a script rules are Outlook features.

What did you need it to do?

0
0
Reply
Emily Cain
May 4, 2022 12:04 pm

Hi, when I select "on this computer only" option in the rules there is no "run" button to select the macro?

0
0
Reply
Josh
March 10, 2021 1:08 pm

I want to run a simply rule that ends in running a script that does the following: when forwarding the message (that always has 1 attachment), rename the subject line of the email to the file name of the attachment. Nothing else. Even with the examples that are posted here, I am unable to get it to work. Please help. Many Thanks. Josh

0
0
Reply
Diane Poremsky
Author
Reply to  Josh
March 10, 2021 2:50 pm

The rule conditions might be able to completely handle choosing which messages to forward - the Forward Attachment & Change Subject
macro above should have adding the attachment name using this line:

  myForward.Subject = oAtt.Filename

Checking the attachment type or attachment name is optional and can be removed.

If you can't get the rule conditions to work, you'll need to add an if statement to the macro to filter out which messages to forward.

0
0
Reply
David
February 12, 2019 8:39 pm

I want to just change the subject line of messages in my mailbox. I've adapted your script and that works OK for the subject shown in the reading pane, but not the subject shown in the message list. This holds even after switching to a different folder and back, or even restarting Outlook. I've looked through the object model (https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem), but don't see any "rebuild the inbox table of subjects" method.

0
0
Reply
Diane Poremsky
Author
Reply to  David
February 12, 2019 11:01 pm

The problem is most likely that you are using the conversation view - it picks the conversation up from the header, not from the subject field.
https://www.slipstick.com/outlook/email/change-the-subject-of-an-incoming-message/#edit

0
0
Reply
kelli stark
February 28, 2018 1:43 am

How can I add a comment on the subject? just into the email I am auto-forward and keeping the original subject in my inbox. you can check the link if you have problems related to the Microsoft support service.

0
0
Reply
Diane Poremsky
Author
Reply to  kelli stark
February 28, 2018 5:36 pm

if you want to edit the subject of the forward, do it like this:
Sub ChangeSubjectForward(Item As Outlook.MailItem)
Set myForward = Item.Forward
myforward.Subject = "Test"
myForward.Recipients.Add "alias@domain.com"

myForward.Send

End Sub

0
0
Reply
Amr
December 10, 2017 4:21 am

Hi,

Is there a way to change the subject and forward the email with no FW in the subject line. Also, could it be forwarded for just emails with a specific words in the subject line rather, or from a specific email, please?

Cheers,

A.E.

0
0
Reply
Elizabeth.vangorkom
September 27, 2017 10:40 am

Hi Diane;

I hope you can help me; I have used the script above as you described (it is all I need to be honest):

"Sub ChangeSubjectForward(Item As Outlook.MailItem)
Item.Subject = "8980 - RCB"
Item.Save

Set myForward = Item.Forward
myForward.Recipients.Add "xxxx@xxx.com"

myForward.Send

End Sub

but what I would like to do is to only run this on a specific sub-folder and then delete the email from said sub-folder after the email has been sent.

Many thanks

0
0
Reply
Diane Poremsky
Author
Reply to  Elizabeth.vangorkom
October 8, 2017 6:03 pm

That is set up as rule... so you can run the rule manually on a folder, but that is not automatic... if you need automatic, you can use an Itemadd macro to watch the folder and do the forward. See https://www.slipstick.com/developer/itemadd-macro/ for a sample.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 25

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.
  • 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
  • Classic Outlook is NOT Going Away in 2026
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

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

Classic Outlook is NOT Going Away in 2026

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