- Subject: macro to reply sometimes fails - why?
- Author: Mark
- Date: 21 Jul 2010
- References:
Hi
I've had help previously with this one from this forum (with great
appreciation)
I've finally come up with the below macro. It works ok sometimes, but
fails on occasions. So far I cannot track down why. Any clues?
Many thanks
Mark
Sub Hi_Name()
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
.HTMLBody = "<span style=""font-family : Arial;font-size :
11pt;color:#1F497D""><p>Hi " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, " ") - 1) & ",</p></span>" & .HTMLBody
End With
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub