Skip to main content

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

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
Kutools for Outlook - Boost Outlook with 100+ Advanced Features for Superior Efficiency
Boost your Outlook 2021 - 2010 or Outlook 365 with these advanced features. Enjoy a comprehensive 60-day free trial 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)
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>" & _
        End If
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.


(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

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

πŸ“§ Email Automation: Out of Office (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: Easily 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   /  Boost Your Outlook Productivity with Tabbed Views  /  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 ...

Over 100 Features Await Your Exploration! Click Here to Discover More.

Read More       Free Download      Purchase


Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
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.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations