The ultimate in lazy emailing?
September 6, 2008 • JP • No Comments • Rate This Article
• Links to this article
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.
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
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
Previous Post: Export Outlook Tasks to Excel
Next Post: Reading worksheet values into arrays



Speak Your Mind
Tell us what you're thinking...Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].