Skip to main content

How to automatically reply to received messages when you are busy in Outlook?

Author: Sun Last Modified: 2020-11-19

Sometimes, you want to automatically reply to the received messages in Outlook while you are busy in a period. But there is no built-in function that can handle this job, however, here I have a VBA code to deal with it.

Auto reply when you are busy with a VBA code


Auto reply when you are busy with a VBA code

Office Tab - Enable Tabbed Editing and Browsing in Microsoft Office, Making Work a Breeze
Unlock Kutools for Outlook's free version now and enjoy over 70 features with unlimited access forever
Boost your Outlook 2021 - 2010 or Outlook 365 with these advanced features. Enjoy 70+ powerful features and elevate your email experience!

Here is a VBA code, which will auto reply while there are some appointments in your Outlook calendar, if there is nothing in the calendar, it stops automatically replying.

1. Press Alt + F11 keys to open Microsoft Visual Basic for Applications window.

2. Double click at ThisOutlookSession from the Project1 pane, copy and paste below code to the script.

VBA: Autoreply while you are busy in calendar

Public WithEvents xInboxItems As Outlook.Items

Private Sub Application_Startup()
Set xInboxItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub xInboxItems_ItemAdd(ByVal Item As Object)
'UpdatebyExtendoffice20180418
Dim xMailItem As Outlook.MailItem
Dim xReplyMailItem As Outlook.MailItem
Dim xReplyHTMLBody As String
Dim xAppointments As Outlook.Items
Dim xFilter As String
Dim xRestrictAppointments As Outlook.Items
Dim xAppointment As Outlook.AppointmentItem
Dim xDateFormat As String
On Error Resume Next
If TypeOf Item Is MailItem Then
    Set xMailItem = Item
    Set xReplyMailItem = xMailItem.Reply
    xReplyHTMLBody = xReplyMailItem.HTMLBody
    Set xAppointments = Outlook.Application.Session.GetDefaultFolder(olFolderCalendar).Items
    xAppointments.Sort "[Start]"
    xAppointments.IncludeRecurrences = True
    xDateFormat = Format(Now, "ddddd h:nn AMPM")
    xFilter = "[Start]<= '" & xDateFormat & "' AND [End]>= '" & xDateFormat & "'"
    Set xRestrictAppointments = xAppointments.Restrict(xFilter)
    If TypeName(xRestrictAppointments) = "Nothing" Then Exit Sub
    For Each xAppointment In xRestrictAppointments
        If xAppointment.BusyStatus = olBusy Or olOutOfOffice Then
            xReplyMailItem.HTMLBody = "<HTML><BODY>I'm Sorry that I can't respond to you right now. I'll reply to you later.</HTML></BODY>" & _
                                      xReplyHTMLBody
            xReplyMailItem.Send
        End If
    Next
End If
End Sub

3. Save this code and restart the Outlook. From now on, if the emails are receiving in the time range of your appointments, an auto reply will be sent.

Tips:

(1) In the code, you can change the reply body as you need in this script "I'm Sorry that I can't respond to you right now. I'll reply to you later." & _

(2) This VBA macro can automatically reply emails received in the Inbox of default data file.


Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!

๐Ÿค– Kutools AI : Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

๐Ÿ“ง Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

๐Ÿ“จ Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

๐Ÿ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

๐ŸŒŸ Interface Magic: ๐Ÿ˜ŠMore Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

๐Ÿ‘ One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  ๐Ÿ•˜Show Sender's Time Zone ...

๐Ÿ‘ฉ๐Ÿผโ€๐Ÿคโ€๐Ÿ‘ฉ๐Ÿป Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Instantly unlock Kutools for Outlook with a single clickโ€”permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2
 

 

 

Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi
How to modify your VBA code for taking into account only all day events with specific names, pls?I've no clue in coding... :(
Thank you in advance.
BR
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations