Set an email has replied - vba

200 Views Asked by At

I have macro to forward an email with the original attachment to everyone which is involved in the original email chain.

    Sub my_test()

Dim objItem As Object

Dim mail As MailItem
Dim forwardMail As MailItem

Dim templateItem As MailItem

For Each objItem In ActiveExplorer.Selection

    If objItem.Class = olMail Then
    
        Set mail = objItem
        Set forwardMail = mail.Forward
        
        Set templateItem = CreateItemFromTemplate("C:\template.oft")
        
        With forwardMail
            .HTMLBody = templateItem.HTMLBody & .HTMLBody
            .To = mail.replyall.To & mail.replyall.CC
            .Display
        End With
        
    End If
    
Next

End Sub

Is it possible to mark this email has "replied" instead of "forwarded" email?

2

There are 2 best solutions below

4
On

yes you need only to change Set forwardMail = mail.Forward to Set forwardMail = mail.Reply

You should also change name of variable forwardMail to replyMail and change all variables in code. full code below.

Sub my_test()

Dim objItem As Object
Dim mail As MailItem
Dim replyMail As MailItem
Dim templateItem As MailItem

For Each objItem In ActiveExplorer.Selection

If objItem.Class = olMail Then

    Set mail = objItem
    Set replyMail = mail.Reply
    
    Set templateItem = CreateItemFromTemplate("C:\template.oft")
    
    With replyMail
        .HTMLBody = templateItem.HTMLBody & .HTMLBody
        .To = mail.replyall.To & mail.replyall.CC
        .Display
    End With
    
 End If

Next

End Sub
0
On

If you mean you want to change the icon to the one that represents "replied", you can change it in the following way...

' Set property PR_ICON_INDEX to 261
objItem.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x10800003", 261
objItem.Save