The ultimate in lazy emailing?


September 6, 2008 – 4:25 pm by JP

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 (see Resend This Message page for instructions). 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.

VBA:
  1. Sub InsertNameInReply()
  2.  
  3. Dim Msg As Outlook.MailItem
  4. Dim MsgReply As Outlook.MailItem
  5. Dim strGreetName As String
  6. Dim lGreetType As Long
  7.  
  8. ' set reference to open/selected mail item
  9. On Error Resume Next
  10. Select Case TypeName(Application.ActiveWindow)
  11.     Case "Explorer"
  12.         Set Msg = ActiveExplorer.Selection.Item(1)
  13.     Case "Inspector"
  14.         Set Msg = ActiveInspector.CurrentItem
  15.     Case Else
  16. End Select
  17. On Error GoTo 0
  18.  
  19. If Msg Is Nothing Then GoTo ExitProc
  20.  
  21. ' figure out greeting line
  22. On Error Resume Next
  23. lGreetType = InputBox("How to greet:" & vbCr & vbCr & "Type '1' for name, '2' for time of day")
  24. On Error GoTo 0
  25.  
  26. If (lGreetType <> 1) And (lGreetType <> 2) Then GoTo ExitProc
  27.  
  28. If lGreetType = 1 Then
  29.   strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
  30. ElseIf lGreetType = 2 Then
  31.   Select Case Time
  32.     Case Is <0.5
  33.       strGreetName = "Good morning"
  34.     Case 0.5 To 0.75
  35.       strGreetName = "Good afternoon"
  36.     Case Else
  37.       strGreetName = "Good evening"
  38.   End Select
  39. End If
  40.  
  41. Set MsgReply = Msg.Reply
  42.  
  43. With MsgReply
  44.   .Subject = "RE:" & Msg.Subject
  45.   .HTMLBody = strGreetName & "," & "<br />" & .HTMLBody
  46.   .Display
  47. End With
  48.  
  49. ExitProc:
  50. Set Msg = Nothing
  51. Set MsgReply = Nothing
  52. strGreetName = vbNullString
  53. End Sub

VBA:
  1. Sub InsertNameInReplyToAll()
  2.  
  3. Dim Msg As Outlook.MailItem
  4. Dim MsgReply As Outlook.MailItem
  5. Dim strGreetName As String
  6. Dim sRecipient As Outlook.Recipient
  7. Dim lGreetType As Long
  8.  
  9. ' set reference to open/selected mail item
  10. On Error Resume Next
  11. Select Case TypeName(Application.ActiveWindow)
  12.     Case "Explorer"
  13.         Set Msg = ActiveExplorer.Selection.Item(1)
  14.     Case "Inspector"
  15.         Set Msg = ActiveInspector.CurrentItem
  16.     Case Else
  17. End Select
  18. On Error GoTo 0
  19.  
  20. If Msg Is Nothing Then GoTo ExitProc
  21.  
  22. ' figure out greeting line
  23. On Error Resume Next
  24. lGreetType = InputBox("How to greet:" & vbCr & vbCr & "Type '1' for name, '2' for time of day")
  25. On Error GoTo 0
  26.  
  27. If (lGreetType <> 1) And (lGreetType <> 2) Then GoTo ExitProc
  28.  
  29. If lGreetType = 1 Then
  30.   strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
  31. ElseIf lGreetType = 2 Then
  32.   Select Case Time
  33.     Case Is <0.5
  34.       strGreetName = "Good morning"
  35.     Case 0.5 To 0.75
  36.       strGreetName = "Good afternoon"
  37.     Case Else
  38.       strGreetName = "Good evening"
  39.   End Select
  40. End If
  41.  
  42. Set MsgReply = Msg.Reply
  43.  
  44. With MsgReply
  45.  
  46.     ' add original recipient(s) to CC field
  47.     For Each sRecipient In Msg.Recipients
  48.       If sRecipient.Name <> "Jimmy Pena" Then
  49.         Set sRecipient = .Recipients.Add(sRecipient.Name)
  50.         With sRecipient
  51.             .Type = olCC
  52.             .Resolve
  53.         End With
  54.       End If
  55.     Next sRecipient
  56.  
  57.   .Subject = "RE:" & Msg.Subject
  58.   .HTMLBody = strGreetName & "," & "<br />" & .HTMLBody
  59.   .Display
  60. End With
  61.  
  62. ExitProc:
  63. Set Msg = Nothing
  64.  
  65. Set MsgReply = Nothing
  66. strGreetName = vbNullString
  67. End Sub

Enjoy,
JP


Share and Enjoy:
  • StumbleUpon
  • Technorati
  • Digg
  • Google
  • del.icio.us
  • MisterWong

Print This Post Print This Post  |  Email This Post Email This Post  |  Permalink  |  Subscribe to this feed Subscribe now!

Filed Under: Outlook, VBA
Tags: ,

This post has 75 views since September 6, 2008 – 4:25 pm.

Post a Comment

To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].





Subscribe without commenting

Keep Reading:

Browse Posts:


« Export Outlook Tasks to Excel || Reading worksheet values into arrays »