1

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).

Community
  • 1
  • 1
H.N.
  • 1,207
  • 2
  • 12
  • 28
  • 1
    https://stackoverflow.com/a/42637793/4539709 – 0m3r Jan 25 '21 at 23:09
  • Tried that still without success. Can anyone help me here? – H.N. Jan 26 '21 at 09:22
  • Given https://stackoverflow.com/questions/65899850/outloook-vba-macro-to-reply-all-with-oft-template, do you still want something from this question? If so, edit this question. – niton Jan 26 '21 at 12:39
  • WHat do you mean? I still could not do it this way. I'd like to know how to use this code, which I have placed here, in order to use the template file body, to reply all. Can you help me? The other thread its a different code for another attempt. So if you could help me here i'd appreciate it. – H.N. Jan 26 '21 at 14:12

1 Answers1

2

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
niton
  • 8,771
  • 21
  • 32
  • 52