The ultimate in lazy emailing?

Lately I've been getting tired of writing a greeting line in every message I send (50-60 per day).

I know that writing someone's name (or a greeting line like "Hello") seems trivial, but it adds up when you send as many emails as I do. It just gets annoying and tiring, especially if you don't mean it :)

Yes, that is how I get a lot of my ideas; just doing something over and over and thinking, "there's got to be a better way." So I adjusted the code found here to insert a greeting line at the top of every email.

I wrote two versions; one for "Reply" and another for "Reply To All". All you do is add these subs to a module in Outlook, then set up a toolbar button to call each macro. When the subs run, you just press 1 if you want to insert the recipient's name at the top, or press 2 if you want a standard greeting line (which self-adjusts depending on time of day). Also if you use the "Reply To All" code, be sure to replace my name with yours (or whatever display name you use to send email from), so you don't send a copy of the message to yourself.

Sub InsertNameInReply()

Dim Msg As Outlook.MailItem
Dim MsgReply As Outlook.MailItem
Dim strGreetName As String
Dim lGreetType As Long

' set reference to open/selected mail item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"
        Set Msg = ActiveExplorer.Selection.Item(1)
    Case "Inspector"
        Set Msg = ActiveInspector.CurrentItem
    Case Else
End Select
On Error GoTo 0

If Msg Is Nothing Then GoTo ExitProc

' figure out greeting line
On Error Resume Next
lGreetType = InputBox("How to greet:" & vbCr & vbCr & "Type '1' for name, '2' for time of day")
On Error GoTo 0

If (lGreetType <> 1) And (lGreetType <> 2) Then GoTo ExitProc

If lGreetType = 1 Then
  strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
ElseIf lGreetType = 2 Then
  Select Case Time
    Case Is < 0.5
      strGreetName = "Good morning"
    Case 0.5 To 0.75
      strGreetName = "Good afternoon"
    Case Else
      strGreetName = "Good evening"
  End Select
End If

Set MsgReply = Msg.Reply

With MsgReply
  .Subject = "RE:" & Msg.Subject
  .HTMLBody = strGreetName & "," & "<br />" & .HTMLBody
  .Display
End With

ExitProc:
Set Msg = Nothing
Set MsgReply = Nothing
strGreetName = vbNullString
End Sub
Sub InsertNameInReplyToAll()

Dim Msg As Outlook.MailItem
Dim MsgReply As Outlook.MailItem
Dim strGreetName As String
Dim sRecipient As Outlook.Recipient
Dim lGreetType As Long

' set reference to open/selected mail item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"
        Set Msg = ActiveExplorer.Selection.Item(1)
    Case "Inspector"
        Set Msg = ActiveInspector.CurrentItem
    Case Else
End Select
On Error GoTo 0

If Msg Is Nothing Then GoTo ExitProc

' figure out greeting line
On Error Resume Next
lGreetType = InputBox("How to greet:" & vbCr & vbCr & "Type '1' for name, '2' for time of day")
On Error GoTo 0

If (lGreetType <> 1) And (lGreetType <> 2) Then GoTo ExitProc

If lGreetType = 1 Then
  strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
ElseIf lGreetType = 2 Then
  Select Case Time
    Case Is < 0.5
      strGreetName = "Good morning"
    Case 0.5 To 0.75
      strGreetName = "Good afternoon"
    Case Else
      strGreetName = "Good evening"
  End Select
End If

Set MsgReply = Msg.Reply

With MsgReply

    ' add original recipient(s) to CC field
    For Each sRecipient In Msg.Recipients
      If sRecipient.Name <> "Jimmy Pena" Then
        Set sRecipient = .Recipients.Add(sRecipient.Name)
        With sRecipient
            .Type = olCC
            .Resolve
        End With
      End If
    Next sRecipient

  .Subject = "RE:" & Msg.Subject
  .HTMLBody = strGreetName & "," & "<br />" & .HTMLBody
  .Display
End With

ExitProc:
Set Msg = Nothing

Set MsgReply = Nothing
strGreetName = vbNullString
End Sub

Enjoy,
JP

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »



Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 1 Comment(s) on The ultimate in lazy emailing?:

  1. nice, I reckon it is not being lazy though, it is that I generally could not be bothered…well done though friend, great stuff.

This article is closed to any future comments.
Peltier Tech Charting Utilities for Excel