• 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
21 Jul 2010macro to reply sometimes fails - why?.Mark
22 Jul 2010\ Re: macro to reply sometimes fails - why?.Ken Slovak
22 Jul 2010   \ Re: macro to reply sometimes fails - why?.Mark
23 Jul 2010      |- Re: macro to reply sometimes fails - why?.Ken Slovak
23 Jul 2010      \ Re: macro to reply sometimes fails - why?.Michael Bednarek
25 Jul 2010         \ Re: macro to reply sometimes fails - why?.Mark
25 Jul 2010            \ Re: macro to reply sometimes fails - why?.Mark
26 Jul 2010               \ Re: macro to reply sometimes fails - why?.Michael Bednarek
28 Jul 2010                  \ Re: macro to reply sometimes fails - why?.Mark
29 Jul 2010                     \ Re: macro to reply sometimes fails - why?.Mark
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)