-
July 11th, 2013, 10:03 AM
#1
Salutation macro for Outlook
Hi,
I am trying to get a Macro to run in Outlook that inserts a salutation/greeting.
When I run it, I am getting a Microsoft Visual Basic box with error:
Run-time error '5': Invalid procedure call or argument
I then click debug and it highlights the following code on line 28:
strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
I am running Win7 Pro with Outlook 2010.
Thanks in advance for any help.
Here is the complete macro:
Sub Greeting()
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 = 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 ' something else entered??
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|