• 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: Reply to a message

Slipstick Systems

› Outlook › Rules, Filters & Views › Run a script rule: Reply to a message

Last reviewed on August 29, 2018     6 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.

rules-icon-13I have a number of sample scripts for Run a Script rules, but not one that replies with a comment. Reply with a template? Sure thing. Change the subject and Forward the message? I've got that. Forward the message body to a new address or reply with a template? I have a script for that.

Now I have a script to automatically reply to a message that does not require a template.

This script requires Word as the email editor. It was tested in Outlook 2013 but should work in Outlook 2007 or 2010, and may work in older versions of Outlook as long as Word is the email editor. The myReply.Body method will work in all versions of Outlook, with both Word or the old Outlook editor.

This code uses Word VBA to insert the text without disturbing the body text. For this reason, it uses Application.ActiveInspector(), so we need to display the message then sending. It will flash on the screen for split second. If this is a problem, you can use the myReply.Body method (below)

Sub ReplywithNote(Item As Outlook.MailItem)

Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olSelection As Word.Selection

Set myReply = Item.Reply
myReply.Display

Set olInspector = Application.ActiveInspector()
Set olDocument = olInspector.WordEditor
Set olSelection = olDocument.Application.Selection

olSelection.InsertBefore "your text"

' uncomment to send
' myReply.Send 

End Sub

Item.Body method

To avoid the screen flash, use this code instead. This code checks the message format and if it's HTML, it uses the HTMLBody property. Plain text messages use the Body property.

Sub ReplytoMessage(Item As Outlook.MailItem)

Set myReply = Item.Forward

If Item.BodyFormat = olFormatHTML Then
    myReply.HTMLBody = "my comment" & vbCrLf & myReply.HTMLBody
 Else
     myReply.Body = "my comment" & vbCrLf & myReply.Body
End If

myReply.Display ' change to send after testing

End Sub

Reply during certain time periods

This version sends replies if the message arrives before or after specified times. To reply during specified times, use And instead:
If Time > #8:00:00 AM# AND Time < #5:00:00 PM# Then

Note: Outlook needs to be running for Run a Script to work!

Sub AutoReplywithTemplate(Item As Outlook.MailItem)

If Time < #8:00:00 AM# Or Time > #12:00:00 PM# Then
Set myReply = Item.Reply
 
myReply.HTMLBody = "my comment" & vbCrLf & myReply.HTMLBody
 
' Change display to send after testing
myReply.Display

End If
 
End Sub

How to use Run a Script

To use this script, set macro security to Low, then open the VBA Editor and paste the code into ThisOutlookSession. Create a Run a Script rule, selecting this rule.

More Information

  • 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: Reply to a message was last modified: August 29th, 2018 by Diane Poremsky

Related Posts:

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

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

Windsurfer (@guest_214852)
March 3, 2020 7:28 am
#214852

Hello
I have emails coming it that have a reply to email address in the properties. Is it possible with a macro to select that email without opening it up and have outlook reply to the email to the reply to email address and insert a template ?
I use outlook 2010 in win 10

0
0
Reply
Ranricht (@guest_203688)
January 3, 2017 4:53 pm
#203688

Hi Diane,
Your website is great and has helped me many times. I am stuck now though and would appreciate your assistance greatly. I need to reply to several hundred messages so need automation. I want the reply message to include the original message and a few added sentences at the top. When I found this page I thought I had it made but I can't get any scripts to run. I have not scripted before in Outlook but have experience coding in other languages. I have the Macro security set to its lowest level, the MS Word Object Library referenced and tried in both Outlook 2013 and Outlook 2010 but nothing. Our exchange servers are Office 365. What should I check? Thanks much!!

0
0
Reply
Octaviano gil (@guest_190606)
April 28, 2015 12:25 pm
#190606

Hi Diane,

Your code has helped me a lot, thank you very much for sharing/teaching.

Now, I have noticed all those emails that the script touched and replied are not marked as if they were, however, the send email resides in the sent items. I wonder if there is a way for the messages that got the automatic reply via rule-macro could be marked in the inbox (just as if you did reply manually), you know, with the purple arrow pointing left?

Thank you in advance for your advice and time.
Octaviano Gil

0
0
Reply
Marc Laflamme (@guest_185289)
August 18, 2014 1:35 pm
#185289

This is exactly what I'm trying to accomplish (reply to selected mail item with precanned text) but it's not working in Outlook 2007. After I create the macro it doesn't even show up in the Macros list unless I remove Item As Outlook.MailItem from Sub ReplytoMessage(Item As Outlook.MailItem) so it just reads Sub ReplytoMessage().

If I remove that then I get an error when running because I don't think myReply is declared. Tried declaring it as Dim myReply As Outlook.Mailitem but that doesn't work either.

Would appreciate some help! I'm very new to VBA scripting.

1
-3
Reply
Diane Poremsky (@guest_185340)
Reply to  Marc Laflamme
August 21, 2014 10:14 am
#185340

This part: Sub ReplytoMessage(Item As Outlook.MailItem) is used to make it work in a rule so the reply is automatic. It's not going to show up in the macros list as it can only be called by another macro.

To use it manually, you need to change the macro to work with the selected item or use a second macro. This macro picks up the selected item and passes it along to the replywithnote macro. To use only one macro, move item as out of the () and dim then set it, like i did, only using item instead of omail.

Sub testreplynote()
Dim oMail As Outlook.MailItem
Set oMail = ActiveExplorer.Selection.Item(1)
ReplywithNote oMail
End Sub

1
-1
Reply
Marc Laflamme (@guest_185347)
Reply to  Diane Poremsky
August 21, 2014 11:19 am
#185347

Thanks Diane - I was able to cobble together some other scripts and eventually got it working. I used the following.

Sub Approved()
Dim approvedReply As Outlook.MailItem
Dim approvedItem As Object

Set approvedItem = GetCurrentItem()
If Not approvedItem Is Nothing Then
Set approvedReply = approvedItem.ReplyAll
approvedReply.HTMLBody = "Approved" & vbCrLf & approvedReply.HTMLBody
approvedReply.Send
End If

Set approvedReply = Nothing
Set approvedItem = Nothing

End Sub

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application

Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select

Set objApp = Nothing

End Function

1
-1
Reply

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

Latest EMO: Vol. 30 Issue 16

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
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Add Attachments and Set Email Fields During a Mail Merge
  • Outlook SecureTemp Files Folder
  • 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.

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