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
1.8k views
in Technique[技术] by (71.8m points)

vba - Outlook Reply or ReplyAll to an Email

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.To = "[email protected]"
objMail.cc = "[email protected]"
objMail.Subject = "Mail test"
objMail.HTMLBody = "This is my message"
unload me
objMail.Display
Set objMail = Nothing
Set objOutlook = Nothing

I am trying to add in another function that help to reply a selected email but can't figure out how I can mix this with Item As Outlook.MailItem I understand that replying an email will require that.

So I would like to know how I can add on so that I can select an email, execute the macro and it will input the recipient email into objMail.To and recipient's body into objMail.HTMLBody

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

To simply Reply or ReplyAll selected messages try the following.

Option Explicit
Sub ReplyMSG()
    Dim olItem As Outlook.MailItem
    Dim olReply As MailItem ' Reply
    Dim olRecip As Recipient ' Add Recipient

    For Each olItem In Application.ActiveExplorer.Selection
    Set olReply = olItem.ReplyAll
    Set olRecip = olReply.Recipients.Add("Email Address Here") ' Recipient Address
        olRecip.Type = olCC
            olReply.HTMLBody = "Hello, Thank you. " & vbCrLf & olReply.HTMLBody
        olReply.Display

        'olReply.Send
    Next olItem
End Sub

To hide the recipient use BCC Example

olRecip.Type = olBcc

To add multiple recipient just add

Set olRecip = olReply.Recipients.Add("Email Here")
Set olRecip = olReply.Recipients.Add("Email Here")
Set olRecip = olReply.Recipients.Add("Email Here")

With out Recipient try the following.

Option Explicit
Sub ReplyMSG()
    Dim olItem As Outlook.MailItem
    Dim olReply As MailItem ' Reply

    For Each olItem In Application.ActiveExplorer.Selection
    Set olReply = olItem.ReplyAll
            olReply.HTMLBody = "Hello, Thank you. " & vbCrLf & olReply.HTMLBody
        olReply.Display

        'olReply.Send
    Next olItem
End Sub

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

...