1

I have written a working code to reply to an email in certain format, however the result is missing some info for the last received email in the Html body (From, sent, to, cc, subject. I'm not even sure if this is called the mail header).

If I click on the Outlook 2013 default 'reply' button, these info would have been auto-generated ahead of the last email, while above it would then be my reply content.

So which function should I use to call these info out? The info must appear in all my replies, so I need to figure it out one way or the other. My code:

'there is a getsignature function before the code.
Public Sub my_reply()
Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objSelection As Outlook.Selection
Dim objMail As Outlook.mailitem
Dim StrSignature As String


StrSignature = GetSignature("C:\Users\xxx\xxx\Microsoft\Signatures\ABC.htm")


Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
For Each objMsg In objSelection
    If objMsg.Class = olMail Then
       objMsg.Categories = "Category A"

Set myreply = objMsg.Reply
myreply.To = objMsg.SenderEmailAddress
myreply.BCC = "xxx@abc" & " ; " & "xxx@abc" 
myreply.Subject = "XYZ matter" & objMsg.Subject
myreply.Display
myreply.HTMLBody = StrSignature & "<br><br>" & objMsg.HTMLBody


Release:
  Set objMsg = Nothing
  Set oExplorer = Nothing
        
     End If
  
    Next

End Sub
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
SS Wong
  • 13
  • 4

1 Answers1

1

ReplyAll should get the cc. If you are only concerned about missing text ignore this.

Set myReply = objMsg.ReplyAll

You are overwriting the initial myreply.HTMLBody with objMsg.HTMLBody

myreply.HTMLBody = StrSignature & "<br><br>" & objMsg.HTMLBody

Instead append to the initial myreply.HTMLBody

Option Explicit

Public Sub my_replyAll()

'Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objSelection As Selection

'Dim objMail As Outlook.mailitem
Dim myReply As mailitem

Dim StrSignature As String

StrSignature = GetSignature("C:\Users\xxx\xxx\Microsoft\Signatures\ABC.htm")

' Set objOL = CreateObject("Outlook.Application")
'Set objSelection = objOL.ActiveExplorer.Selection
Set objSelection = ActiveExplorer.Selection

For Each objMsg In objSelection

    If objMsg.Class = olMail Then

        Set myReply = objMsg.ReplyAll

        myReply.To = objMsg.SenderEmailAddress

        myReply.BCC = "xxx@abc" & " ; " & "xxx@abc"

        myReply.Subject = "XYZ matter " & objMsg.Subject

        myReply.Display

        'myReply.HtmlBody = StrSignature & "<br><br>" & objMsg.HtmlBody
        myReply.HtmlBody = StrSignature & "<br><br>" & myReply.HtmlBody

Release:
        Set objMsg = Nothing

    End If

Next

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52