I 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
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.
- 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 Appointment From Email Automatically
- Delegates, Meeting Requests, and Rules
- 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
- 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: Change Subject then Forward 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
- Sort messages by Sender domain
- To create a rule with wildcards
- Use a Rule to delete older messages as new ones arrive