【发布时间】:2016-02-05 16:56:48
【问题描述】:
我有一份每隔几天收到的邮件列表,主题如下:
- 客户订单1-04/11/2015
- 客户订单2-04/11/2015
- 客户订单 3-04/11/2015
- 客户订单1-03/11/2015
- 客户订单2-03/11/2015
- 客户订单 3-03/11/2015
我只想在主题是 CUSTOMER ORDERS1 并且 04/11/2015 = 今天日期 - 1 时做某事。
我想我需要
- 从主题中提取文本日期,然后将其转换为日期格式 DD/MM/YYYY 然后将该日期与该格式的当前 -1 进行比较。
- 我还需要从主题中提取 CUSTOMER ORDERS1,并将其与“CUSTOMER ORDERS1”进行比较。
下面是代码
Public Sub saveAttachtoDisk()
Dim olApp As Outlook.Application, _
oNS As Outlook.NameSpace, _
oFld As Outlook.Folder, _
oMails As Outlook.Items, _
oMail As Outlook.MailItem, _
oAtt As Outlook.Attachment, _
SaveFolder As String, _
Yesterday as String
SaveFolder = "d:\temp\"
Yesterday = Format(Now()-1, "mm.dd.yy")
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
Set oNS = olApp.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderInbox)
Set oMails = oFld.Items
For Each oMail In oMails
If InStr(1, oMail.Subject, yesterday)
and InStr(1, oMail.Subject, 'CUSTOMER ORDERS1') Then
'----Your code comes here
For Each oAtt In oMail.Attachments
oAtt.SaveAsFile SaveFolder & "\" & oAtt.DisplayName
Set oAtt = Nothing
Next oAtt
Else
End If
Next oMail
End Sub
【问题讨论】:
-
您尝试从主题行中提取日期和其他值是什么?