【发布时间】:2015-02-20 20:28:15
【问题描述】:
我每个星期三都会收到一封来自特定发件人的邮件。这封电子邮件的主题有时会发生变化
主题“暴露声明 - COB 20150217”的示例 #1
主题“Margin Notice COB 2015-Feb-10”的示例 #2
发件人附加的日期是我收到邮件的前一天。
我有以下代码,它可能会搜索该电子邮件,然后使用自定义正文文本回复它,但我无法让代码在主题中找到具有该日期的特定消息。
有没有办法通过主题以外的其他参数进行搜索?
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
但它不起作用......
这是唯一能让我找到确切消息的搜索组合(SenderEmailAddressthat 和 ReceivedTime)...
【问题讨论】:
-
确保您已完成How to automate Outlook from another program 文章中描述的所有步骤。
-
您可以访问和过滤 MaiItem 类的任何属性(这里是完整列表):msdn.microsoft.com/en-us/library/… 但您没有指定您要过滤的具体内容。顺便说一句:您最近的编辑完全改变了问题的意义,所以答案没有任何意义。您应该已将新代码粘贴到原始问题下方。
-
这就是为什么我问把更新的代码放在哪里......我搞砸了...... :(
-
第二部分
olMail.ReceivedTime = Now()因为您试图过滤在运行宏时收到的消息。如果您想要当天的消息,那么olMail.ReceivedTime>Date()应该可以工作 -
是的,谢谢。如果发件人在当天第一封邮件之后给我发了另一封邮件怎么办? :)
标签: excel vba email outlook reply