Macro Intro
We are busy, sometimes too busy to type a friendly Greeting and Goodbye in our emails. This Outlook macro automates the entry of a Greeting “Good Morning” or “Hello” at the beginning of your emails. At the end of your email this macro automatically enters a Goodbye “Have a good night!” and “Enjoy your weekend!”. The appropriate entries are determined based on the current time and the day of the week. The Greeting and Goodbye macro helps you deliver better customer service and create better connections with your clients! This macro can be fired from a custom button or trigger automatically when replying to an email. The VBA code is easy to customize allowing you to edit or add additional Greetings and Goodbyes.See it in Action
Watch this video to see this macro in action.Code
Here is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Outlook 16.0 Object Library, Microsoft Word 16.0 ObjectInsider Content
Here is the Insider code for this macro. This code will allow you to setup an Excel Workbook to manage the Greeting and Goodbye text you want to pull into your Outlook emails! In the Excel Workbook you will be able to make changes to when certain Greetings and Goodbyes should display based on the Day of the Week and Time of the Day. Your Greetings and Goodbyes should be listed in different Excel Worksheets to separate the criteria.The criteria that determines when a Greeting or Goodbye displays includes: Weekdays, Time of Day – Lower Bound, and Time of Day – Upper Bound. For the Weekdays criteria you can list multiple days using “;” to separate the days. (Example: If you want a Greeting to only trigger on weekdays list Monday;Tuesday;Wednesday;Thursday;Friday in the Weekday column of the Greeting Excel Worksheet) Next for the Time of Day – Lower and Upper Bounds criteria you can determine when the Greeting or Goodbye should fire if the Time of Day falls between these two bounds. To extend a bound beyond a specific time you can leave the Lower or Upper Bound columns blank.
***Tip: When setting up your display criteria ensure you are listing the most specific criteria in the second row under the header columns. This will ensure that the criteria is always evaluated before moving on to less specific rows.
Customization
These segments of code can be customized to personalize this macro.These lines of code (22 through 32) can be customized to personalize this macro.
Update the TimeofDay to get your Greeting and Goodbye to fire at specific times. You can also indicate certain Greetings or Goodbyes to be generated based on the Weekday within these lines of code.
Update the TimeofDay to get your Greeting and Goodbye to fire at specific times. You can also indicate certain Greetings or Goodbyes to be generated based on the Weekday within these lines of code.
The EmailBody variable is the final string that will be entered into your email body. This code can be updated to add or remove vbNewLine to update spacing in the Outlook Email body.
Although you can create a custom button to trigger the Greeting and Goodbye macro on command you can also automate this macro with some additional VBA code.
Here is the additional code that can be used to fire this macro with Outlook’s Reply and Reply All buttons. You also must make your GreetingGoodbye macro Public so it can be called within your Outlook Session. To do this simply add the word “Public” in front of Sub GreetingGoodbyeFreeMacro()
Copy and Paste this VBA code into your Outlook Session and restart Outlook. [code lang=”vb”]’Leverage & Lean “Less Clicks, More Results” Option Explicit Private WithEvents oExpl As Explorer Private WithEvents oItem As MailItem Dim bDiscardEvents As Boolean Dim oResponse As MailItem Private Sub Application_Startup() Set oExpl = Application.ActiveExplorer bDiscardEvents = False ‘Call the Macros listed below: ‘Call MacroName End Sub Private Sub oExpl_SelectionChange() On Error Resume Next Set oItem = oExpl.Selection.Item(1) End Sub Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) On Error GoTo LeverageLean Cancel = True bDiscardEvents = True ‘Display current email selection Set oResponse = oItem.Reply oResponse.Display ‘Call the Macros listed below: ‘Call MacroName Exit Sub LeverageLean: End Sub Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean) On Error GoTo LeverageLean Cancel = True bDiscardEvents = True ‘Display current email selection Set oResponse = oItem.ReplyAll oResponse.Display ‘Call the Macros listed below: ‘Call MacroName Exit Sub LeverageLean: End Sub ‘Stay Awesome![/code]
Here is the additional code that can be used to fire this macro with Outlook’s Reply and Reply All buttons. You also must make your GreetingGoodbye macro Public so it can be called within your Outlook Session. To do this simply add the word “Public” in front of Sub GreetingGoodbyeFreeMacro()
Copy and Paste this VBA code into your Outlook Session and restart Outlook. [code lang=”vb”]’Leverage & Lean “Less Clicks, More Results” Option Explicit Private WithEvents oExpl As Explorer Private WithEvents oItem As MailItem Dim bDiscardEvents As Boolean Dim oResponse As MailItem Private Sub Application_Startup() Set oExpl = Application.ActiveExplorer bDiscardEvents = False ‘Call the Macros listed below: ‘Call MacroName End Sub Private Sub oExpl_SelectionChange() On Error Resume Next Set oItem = oExpl.Selection.Item(1) End Sub Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) On Error GoTo LeverageLean Cancel = True bDiscardEvents = True ‘Display current email selection Set oResponse = oItem.Reply oResponse.Display ‘Call the Macros listed below: ‘Call MacroName Exit Sub LeverageLean: End Sub Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean) On Error GoTo LeverageLean Cancel = True bDiscardEvents = True ‘Display current email selection Set oResponse = oItem.ReplyAll oResponse.Display ‘Call the Macros listed below: ‘Call MacroName Exit Sub LeverageLean: End Sub ‘Stay Awesome![/code]