- Subject: Re: macro to reply sometimes fails - why?
- Author: Mark
- Date: 29 Jul 2010
- References:
1
2
3
4
5
6
7
8
Thanks all for your help.
For the sake of anyone else who wants to play with it, the following
is what I came up with and it works for me, but no guarantees for
anybody else.
I have put buttons on my task bar. Actually I have a few: Dear,
Dear_reply_all, Hi, Hello, Many thanks. All have differing salutations
etc.
Dear_reply_all uses Set NewMsg = myItem.ReplyAll
-----------------------
Sub Dear_Name_if()
Dim myItem As Outlook.MailItem
Dim NewMsg As Outlook.MailItem
' get valid ref to current item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set myItem = ActiveExplorer.Selection.Item(1)
myItem.Display
Case "Inspector"
Set myItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If myItem Is Nothing Then
MsgBox "Could not use current item. Please select or open a
single email.", _
vbInformation
GoTo ExitProc
End If
Set NewMsg = myItem.Reply
With NewMsg
NewMsg.BodyFormat = olFormatHTML
.HTMLBody = "<span style=""font-size:11.0pt;font-family:
Arial;color:#1F497D""><p>Regards, Mark" & vbCr & vbCr & vbCr & vbCr &
"</p>" & .HTMLBody
.HTMLBody = "<span style=""font-size:11.0pt;font-family:
Arial;color:#1F497D""><p> " & "</p><br />" & .HTMLBody
If myItem.SenderName, " " Then
.HTMLBody = "<span style=""font-family : Arial;font-size :
11pt;color:#1F497D""><p>Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, " ") - 1) & ",</p></span>" & .HTMLBody
Else
.HTMLBody = "<span style=""font-family : Arial;font-size :
11pt;color:#1F497D""><p>Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, "@") - 1) & ",</p></span>" & .HTMLBody
End If
End With
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub