Sub Merge_daily_emails1()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim Atch As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Dim filteredItems As Outlook.Items
Dim itm As Object
Dim strFilter As String
strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%Daily Reports%'"
Set filteredItems = myInbox.Items.Restrict(strFilter)
AttachmentPath = "H:\"
If filteredItems.count > 0 Then
For Each itm In filteredItems
If itm.Attachments.count <> 0 Then
For Each Atch In itm.Attachments
Atch.SaveAsFile AttachmentPath & Atch.Filename
Exit For
Next
Else
MsgBox "Does not Have an Attachment"
End If
Next
End If
Set myOlApp = Nothing
End Sub
嗨,我看到我正在尝试从我的收件箱电子邮件中下载其主题行中包含“每日报告”字样的所有附件。我面临的问题是,我下载的某些文件(excel)的大小 0kb ,其名称为“@”,而当我打开时他们看起来很开放。我尝试后最好的猜测是因为这封电子邮件很旧并且使用企业保险库系统打开,我无法以正确的方式下载文件。有没有人遇到类似的情况?
编辑(ddate as Date)参数是我用于搜索的开始日期,我删除了代码以使其更简单,现在它将搜索整个收件箱。
答案 0 :(得分:0)
您可以从子文件中删除(ddate As Date)
并将AttachmentPath
声明为Dim attachmentPath As String
,同时将选项明确设置为关闭通常不是一种好习惯