Excel VBA,如何回复特定的电子邮件

我收到一封邮件,每星期三从一个特定的发件人。 这封电子邮件的主题有时会改变

“暴露声明 – COB 20150217”主题的示例#1

“保证金通知COB 2015-Feb-10”主题的示例#2

发件人追加的date是我收到邮件前一天。

我有下面的代码,可能会search该电子邮件,然后用自定义正文文本回复它,但我无法设法让代码find与该date在该主题的特定消息。

有没有一种方法可以通过除主题之外的其他参数进行search?

Sub ReplyMail_No_Movements() Dim olApp As Outlook.Application Dim olNs As Namespace Dim Fldr As MAPIFolder Dim olMail As Variant Dim SigString As String Dim Signature As String Dim i As Integer Set olApp = New Outlook.Application Set olNs = olApp.GetNamespace("MAPI") Set Fldr = olNs.GetDefaultFolder(olFolderInbox) i = 1 SigString = Environ("appdata") & _ "\Microsoft\Signatures\MCC.txt" If Dir(SigString) <> "" Then Signature = GetBoiler(SigString) Else Signature = "" End If On Error Resume Next For Each olMail In Fldr.Items If InStr(olMail.Subject, "Exposure Statement - COB date") <> 0 Then 'where date is a date that changes every wednesday With olMail.Reply .to = "email1@domain.com;email2@domain.com" .CC = "email3@domain.com;email4@domain.com" .Body = "Dear All," & Chr(10) & _ Chr(10) & "we agree with your portfolio here attached and according to it we see no move for today." & _ Chr(10) & " Best Regards." & _ Chr(10) & _ Chr(10) & Signature .Display End With i = i + 1 End If Next olMail End Sub 

编辑:我改变了这个代码位

 If InStr(olMail.Subject, "Exposure Statement - COB date") <> 0 Then 

 If olMail.SenderEmailAddress = "email1@gdomain.com" And olMail.ReceivedTime = Now() Then 

但是这不起作用…

这是唯一的search组合(SenderEmailAddressthat和ReceivedTime),让我find确切的消息…

你应该使用:工具 – >参考。 findMicrosoft Outlook 15.0 Object Library ,检查它并closures窗口。

或者只是使用后期绑定

 Const olFolderInbox = 6 Sub Test() Dim olApp As Object Dim olNs As Object Dim Fldr As Object Dim olMail Dim i As Long Set olApp = CreateObject("Outlook.Application") Set olNs = olApp.GetNamespace("MAPI") Set Fldr = olNs.GetDefaultFolder(olFolderInbox) i = 1 For Each olMail In Fldr.Items If InStr(olMail.Subject, "email message object text") <> 0 Then olMail.Display olMail.ReplyAll i = i + 1 End If Next olMail End Sub