Outlook Greeting and Goodbye | VBA Macro #13

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 Object

Insider 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.
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]
Search

First time using VBA?

The Developer Tab is an additional section of the ribbon when activated allows you access to Visual Basic in Applications like Access, Excel, Outlook, PowerPoint, Word.
Setup Now
Once the Developer Tab is available you will have the capability to update your security to allow Macros to run in the current application.
Setup Now
A sub of code is a collection of objects and variables. For the code to successfully run a library of references needs to be set.
Setup Now
Subscribe as an Insider to receive additional rights.
If you like our content and want to show your support tip us here!

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Powered By MemberPress WooCommerce Plus Integration

Free Macro

Start creating Less Clicks, More Results today!