简体   繁体   English

从 Excel 回复 Outlook 邮件

[英]Reply to Outlook mail from Excel

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.这类似于我们在 Outlook 中打开邮件并单击“全部回复”按钮。

I want it triggered from Excel.我希望它从 Excel 触发。

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.然后您将能够访问olMail项目的所有属性。 One of which is .ReplyAll其中之一是.ReplyAll

ScreenShot截屏

在此处输入图片说明

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

    DoEvents

    '
    '~~> Rest of the code
    '

    i = i + 1
End If

There is a ReplyAll method which returns a mail object.有一个ReplyAll方法返回一个邮件对象。 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.未测试,但应该接近。

Try this one:试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM