下面的VBA代码映射到" test" Outlook中我的收件箱中的文件夹。我需要它映射到" TAT Monitor"文件夹是Outlook中公用文件夹中的子文件夹(公用文件夹> ABC文件夹> 123文件夹> Tat监视文件夹)。我试着插入" 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
答案 0 :(得分:1)
请参阅https://msdn.microsoft.com/en-us/library/office/ff867877.aspx
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.("ABC Folder").Folders.("123 Folder").Folders.("Tat Monitor Folder")
删除默认&#34;项目&#34;
时的错字Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("ABC Folder").Folders("123 Folder").Folders("Tat Monitor Folder")
与
相同Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("ABC Folder").Folders.Item("123 Folder").Folders.Item("Tat Monitor Folder")