【发布时间】:2016-07-14 00:27:34
【问题描述】:
下面的 VBA 代码映射到 Outlook 收件箱中的“测试”文件夹。我需要它映射到“TAT Monitor”文件夹,该文件夹是我的 Outlook 公用文件夹中的子文件夹(公用文件夹>ABC 文件夹>123 文件夹>Tat Monitor 文件夹)。我尝试插入“olPublicFoldersAllPublicFolders”代替“olFolderInbox”,但它无法识别它。
Public Sub GetAttachments()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim firstDate As Date
Dim secondDate As Date
Dim i As Integer
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("Test")
firstDate = Date - 1 + TimeValue("8:00:00am")
secondDate = Date - 1 + TimeValue("8:30:00am")
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Item.SentOn > firstDate And Item.SentOn < secondDate Then
FileName = "C:\Users\user1\Desktop\TEST2\" & Atmt & ".xlsx"
Atmt.SaveAsFile FileName
Else
End If
Next
Next
Set Inbox = Nothing
End Sub
【问题讨论】: