Reply all with attachment

1.1k views Asked by At

I have this code to a vba outlook macro to reply all.

Sub my_test()

Dim objItem As Object

Dim mail As MailItem
Dim replyall As MailItem

Dim templateItem As MailItem

For Each objItem In ActiveExplorer.Selection

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

End Sub

I am trying to add a functionality so that when the original email brings an attachment (docx, pdf), when I reply all using this macro it will also use the original attachment and place it as an attachment in the reply all email. How can I achieve this?

1

There are 1 answers

3
niton On BEST ANSWER

Forward then populate the .To with what would appear in a ReplyAll.

Option Explicit

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
            .To = mail.replyall.To & ";" & mail.replyall.CC
            .Display
        End With
        
    End If
    
Next

End Sub