2

我正在尝试使用正文中的给定格式“回复所有”。

我使用以下代码来搜索和显示邮件。

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

我需要用相同的主题和规定的正文和签名全部回复。

这类似于我们在 Outlook 中打开邮件并单击“全部回复”按钮。

我希望它从 Excel 触发。

4

3 回答 3

1

由于您使用的是早期绑定,因此更改

Dim olMail As Variant

Dim olMail As Outlook.MailItem

然后您将能够访问该olMail项目的所有属性。其中之一是.ReplyAll

截屏

在此处输入图像描述

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

    DoEvents

    '
    '~~> Rest of the code
    '

    i = i + 1
End If
于 2014-08-11T09:44:14.050 回答
0

有一个返回邮件对象的ReplyAll方法。见这里
因此,如果您正在遍历一些邮件,那么这应该可以工作:

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

未经测试,但应该接近。

于 2014-08-11T09:46:39.433 回答
0

试试这个:

olMail.ReplyAll
olMail.ReplyAll.body = bodyMail & vbLF & .body
于 2015-08-28T06:40:04.097 回答