This is an Outlook macro that is the combination of two existing Outlook macros Greeting and Goodbye [VBA Macro #13] and Hello Contacts [VBA Macro #33]. Starting an email with a Greeting or ending it with a Goodbye can look more personable with some VBA code! The Greeting and Goodbye Contact macro automates the entry of a Greeting “Good Morning” or “Hello” followed by the First Name of the recipient you are emailing. To identify the First Name this macro uses the recipient’s email address to loop through all the existing contact records for a matching email address. If a match is found the contact’s First Name field value is used in the beginning of the email. To utilize the Greeting and Goodbye Contacts macro, you will need to add contacts in Outlook. If you haven’t created an Outlook contact before checkout this link to see the multiple ways to do this. You can create a contact directly from an email message, with an import, or manually from scratch. The appropriate Greeting and Goodbye is determined by the current time and the day of the week. The Greeting and Goodbye Contacts macro helps you deliver better customer service and create better connections with your clients! This Outlook macro can be fired from a custom button or trigger automatically when replying to an email.
32 through 41: 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.
62 through 65: GreetingGoodbyeContacts is the final string that will be entered into your email body. Here is where you can update spacing by adding or removing vbNewLine.
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 you used to fire this macro with Outlook’s Reply and Reply All buttons. Copy and Paste this VBA code into your Outlook Session and restart Outlook. You must make your GreetingGoodbye macro Public so it can be called within your Outlook Session.[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]
See it in Action!
Watch this video to see this macro in action.The 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 Office 16.0 Object Library, Microsoft Word 16.0 Object LibraryMacro Monday
Here is the Macro Monday video this macro was featured in. Watch this video to learn how to get the most out of this macro and start using it today!Customization
These lines of code can be customized to personalize this macro. These lines of code can be customized to personalize this macro.32 through 41: 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.
62 through 65: GreetingGoodbyeContacts is the final string that will be entered into your email body. Here is where you can update spacing by adding or removing vbNewLine.
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 you used to fire this macro with Outlook’s Reply and Reply All buttons. Copy and Paste this VBA code into your Outlook Session and restart Outlook. You must make your GreetingGoodbye macro Public so it can be called within your Outlook Session.[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]