Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

excel - Outlook Reply to All Macro using a template

I'm trying to create a macro 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).

I am not sure how to use my template, so when I reply in the bottom I wanted to have the original email and in the top of the email body I wanted to have 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).

question from:https://stackoverflow.com/questions/65893485/outlook-reply-to-all-macro-using-a-template

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:emplate.oft")
        
        With replyall
            .HTMLBody = templateItem.HTMLBody & .HTMLBody
            .Display
        End With
        
    End If
    
Next

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...