|
|
|
|
|
|
Outlook
|
Insert Recipient's name in reply
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2003
|
Submitted by:
|
JP2112
|
Description:
|
This code programmatically creates a reply message and inserts either a time-based greeting, or the recipient's name, depending on end user selection. Message is displayed on-screen so it can be customized with reply.
|
Discussion:
|
I use this code when blowing through my Inbox, because after a while it gets tedious to keep typing "Hello" or "Good afternoon" or whatever the case may be. Nowadays even the niceties can be automated. With this code you can focus on content instead of presentation.
|
Code:
|
instructions for use
|
Sub InsertNameInReply()
Dim Msg As Outlook.MailItem
Dim MsgReply As Outlook.MailItem
Dim strGreetName As String
Dim lGreetType As Long
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
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 = False 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
Else
Goto ExitProc
End If
Set MsgReply = Msg.Reply
With MsgReply
.Subject = "RE:" & Msg.Subject
.HTMLBody = "<span style=""font-family : verdana;font-size : 10pt""><p>Hello " & strGreetName & ",</p></span>" & .HTMLBody
.Display
End With
ExitProc:
Set Msg = Nothing
Set MsgReply = Nothing
End Sub
|
How to use:
|
- Go to Outlook's VBIDE (press Alt-F11) and paste the code into a standard module (Insert>Module). You can then assign it to a toolbar button as follows. You can use it immediately, although I recommend closing and restarting Outlook.
- While viewing an email or in the main Explorer window, hover your mouse pointer over a toolbar, right-click and choose 'Customize'. Or go to View>Toolbars>Customize. On the "Commands" tab, in the "Categories" list, click "Macros." The list of macros you created should appear.
- Click and drag the appropriate macro to the toolbar of your choice. If you are in the main Explorer window, this would either be the Standard or Advanced toolbar. If you are viewing a email, it would be either the Standard or Formatting toolbar.
- Once you drop the macro on the toolbar, right-click it and customize the display name, icon, etc. I usually name the button "Reply with Name" or "Reply With Greeting."
- You should only run the code when viewing a single open email, or have one email selected in an Explorer window. Otherwise the code will simply exit silently.
- The code uses the HTMLBody Property to manipulate the reply. If you write in Plain or Rich Text, you'll have to adjust the code in the With block. In either case, the variable "strGreetName" will contain the opening line text.
|
Test the code:
|
|
Sample File:
|
No Attachment
|
Approved by mdmackillop
|
This entry has been viewed 180 times.
|
|