How to Auto Add Greetings to Reply Messages with Outlook VBA

In general, when replying an email, we get used to adding the greetings. Someone even hopes that Outlook can auto add greetings depending on the recipient name. Actually it can be realized with Outlook VBA. This article will introduce it in detail.

As normal, when we reply an email, we will always write some greetings at the beginning of the message body. You may feel it a bit cumbersome since you don’t want to type the same greeting line every time. In reality, you can avoid it via Outlook “Quick Parts” feature, which permits you to save the same greetings as Quick Part. Since then, you can directly insert it without needs to type manually.Add Greetings Via Quick Parts

However, this function is unable to auto identify the recipient, so it cannot add a personalized greeting, namely includes the recipient name. Also, some users still want to make it totally automatic even without them inserting manually. Focused on this kind of requirement, here is a quick method to achieve it via Outlook VBA.

Auto Add Greetings to Reply Messages

  1. In the first place, launch Outlook and switch to “Developer” tab.
  2. Then you need to click on the “Visual Basic” button.
  3. Subsequently, a new window will show up. Then in it, you ought to open a blank module or insert a new module.
  4. Next in the new module, you can copy and paste the following VBA codes into it.
Sub AutoAddGreetingtoReply()
    Dim oMail As MailItem
    Dim oReply As MailItem
    Dim GreetTime As String
    Select Case Application.ActiveWindow.Class
           Case olInspector
                Set oMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set oMail = ActiveExplorer.Selection.Item(1)
    End Select
    Select Case Time
           Case 0.3 To 0.5
                GreetTime = "Good morning!"
           Case 0.5 To 0.75
                GreetTime = "Good afternoon!"
           Case Else
                GreetTime = "Good evening!"
    End Select
    Set oReply = oMail.Reply
    With oReply
         .HTMLBody = "<HTML><Body>Dear " & oMail.SenderName & ", </HTML></Body>" & GreetTime & .HTMLBody
    End With
End Sub

VBA Codes - Auto Add Greetings to Reply Messages

  1. After that, you can exit the current window and change your macro settings. Click on the “Macro Security” button and then set the macro level to be low.
  2. Later you need to add the new VBA project to ribbon or Quick Access Toolbar. Here we will take Quick Access Toolbar as an example.
  • Firstly, click down arrow in Quick Access Toolbar and select “More Commands”.
  • Then in popup window, add the new macro to Quick Access Toolbar by following the steps shown in the image below.Add the AutoAddGreetingtoReply Macro to Quick Access Toolbar
  1. Eventually, you can have a try.
  • Firstly, select an email and hit the macro button in Quick Access Toolbar.Click the macro button
  • Then a new reply message will pop up. Greetings have been added to the message body automatically, like the following image.Automatic Greetings

Keep Your Outlook Well-Protected

As Outlook is vulnerable, regular users must have encountered multiple issues. If faced with these annoying errors, then we can smartly make use of the inbuilt repair tool, scanpst.exe, which can deal with the small troubles. If you encounter serious issues, like Outlook mail damage, the inbox tool will not be a lot of help. You will be required to resort more experienced and intelligent tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair corrupt SQL mdf file and outlook repair software products. For more information visit

One response to “How to Auto Add Greetings to Reply Messages with Outlook VBA”

  1. I think this macro could be super improved if it is trigered from the reply action instead of from another button

Leave a Reply

Your email address will not be published. Required fields are marked *