Reply to Outlook mail from Excel

风流意气都作罢 提交于 2019-12-07 19:01:45

问题


I am trying to "replytoall" with a given format in the Body.

I use the following code to search for and display the mails.

Sub Test()

Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1

For Each olMail In Fldr.Items
If InStr(olMail.Subject, "Application for Privilege Leave - Leave ID - Dev-PL-45252-4") <> 0 Then
olMail.Display

i = i + 1
End If
Next olMail
End Sub

I need to Replyall with the same subject and a prescribed body and signature.

It is similar to when we open up a mail in Outlook and click on the Reply to All button.

I want it triggered from Excel.


回答1:


Since you are using Early Binding, Change

Dim olMail As Variant

to

Dim olMail As Outlook.MailItem

And then you will be able to access all the properties of the olMail item. One of which is .ReplyAll

ScreenShot

If InStr(olMail.Subject, "Blah Blah") <> 0 Then
    olMail.Display
    olMail.ReplyAll

    DoEvents

    '
    '~~> Rest of the code
    '

    i = i + 1
End If



回答2:


There is a ReplyAll method which returns a mail object. See here.
So if you are iterating through some mails, then this should work:

For Each oMail in Fldr.Items
    If InStr(olMail.Subject, "mysubject") <> 0 Then
        With oMail.ReplyAll
            .Subject  = oMail.Subject '~~> this is optional
            .Body = "your Body"
            '~~> all other stuff you need your mail to have
            .Display '~~> change to .Send if it is already ok
        End With
    End If
Next

Not tested but should be close.




回答3:


Try this one:

olMail.ReplyAll
olMail.ReplyAll.body = bodyMail & vbLF & .body


来源:https://stackoverflow.com/questions/25238635/reply-to-outlook-mail-from-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!