Reply to the sender of an email using VBA in Outlook

If you’ve ever found yourself repeatedly responding to emails with similar messages, this post is for you.

We’re diving into the world of automating responses with VBA, a powerful tool that can save you time and streamline your communication.

Whether you’re a VBA novice or looking to expand your skills, this guide will walk you through the steps to create a custom solution for replying to emails quickly and efficiently.

VBA Code

Sub ReplyToSender()
    Dim mail As Outlook.MailItem
    Dim reply As Outlook.MailItem

    If Application.ActiveExplorer.Selection.Count > 0 Then
        Set mail = Application.ActiveExplorer.Selection.Item(1)
        If mail.Class = olMail Then
            Set reply = mail.Reply
            With reply
                .Body = "Your custom message here" & vbCrLf & .Body
            End With
        End If
    End If
End Sub

Code Explanation

  • Sub ReplyToSender(): This line starts our subroutine, named ‘ReplyToSender’.
  • Dim mail, reply As Outlook.MailItem: Here, we declare two variables, ‘mail’ and ‘reply’, as Outlook MailItem objects.
  • Application.ActiveExplorer.Selection: This part checks if there’s a selected email in Outlook.
  • Set mail = …: Assigns the selected email to the ‘mail’ variable.
  • mail.Reply: Creates a reply to the selected email.
  • .Body = “Your custom message here”: Adds a custom message to the beginning of the reply.
  • .Display: Opens the reply in a new window for you to review before sending.

Adding VBA to the Editor

  1. Open Outlook and go to the Developer tab.
  1. Click on Visual Basic to open the VBA editor.
  1. In the Project window, right-click on your Outlook session and select Insert >> Module.
  1. Copy and paste the provided VBA code into the module window.
  2. Close the editor and return to Outlook.

Post-Script: Executing the VBA Code

After inserting the VBA code into the editor, follow these steps to use it:

  1. Return to Outlook: Go back to your Outlook window.
  2. Select an Email: Click on the email you want to reply to.
  3. Run the Script: Press Alt + F8, select ReplyToSender, and click Run.
  4. Edit and Send: The reply email window will open with a pre-defined message. Edit as needed and send.


Today, we explored how VBA can transform your email management in Outlook, particularly in responding to messages.

This approach not only boosts efficiency but also ensures consistency in your replies.

While VBA comes with its learning curve, the long-term benefits it offers are well worth the effort.

Give it a try, and you might find that it significantly streamlines your email communication process.

Related Articles