How to Reply to All using a template?

779 views Asked by At

I'm trying to do a "reply all" command using a specific template.

This is what I have so far:

Sub my_test()
    
    Dim mail 'object/mail item iterator
    Dim replyall 'object which will represent the reply email
    
    For Each mail In Outlook.Application.ActiveExplorer.Selection
        If mail.Class = olMail Then
            Set replyall = mail.replyall
            With replyall
                .Body = "My template from a oft file"
                .Display
            End With
        End If
    Next
    
End Sub

In the body, I'd like to use a template which I have in a oft file in c:\mytemplate.oft.

When I reply, in the bottom I want the original email and in the top of the email body I want the text from the existing template.

The idea is to use this code (if possible), and place the context of the template body file (text and a table), inside of this reply email (in the top).

1

There are 1 answers

0
niton On BEST ANSWER

Code for Outlook. No apparent purpose for the Excel tag.

Option Explicit

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