我正在尝试"回复所有"在Body中使用给定的格式。
我使用以下代码搜索并显示邮件。
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触发它。
答案 0 :(得分: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
答案 1 :(得分:0)
有一个 ReplyAll 方法,它返回一个邮件对象。 See here。
因此,如果您正在迭代一些邮件,那么这应该有效:
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
未经测试但应该关闭。
答案 2 :(得分:0)
试试这个:
olMail.ReplyAll
olMail.ReplyAll.body = bodyMail & vbLF & .body