本文介绍了在VBA中引用Outlook的“公用"文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的VBA代码映射到Outlook中我的收件箱中的测试"文件夹.我需要它映射到"TAT Monitor"文件夹,该文件夹是Outlook公用文件夹中的子文件夹(公共文件夹">"ABC文件夹">"123文件夹">"Tat Monitor"文件夹).我尝试插入"olPublicFoldersAllPublicFolders"代替"olFolderInbox",但无法识别.
The VBA code below maps to the "test" folder in my inbox in Outlook. I need it to map to the "TAT Monitor" folder which is a sub folder in the public folder in my Outlook(Public Folder>ABC Folder>123 Folder>Tat Monitor Folder). I tried plugging in "olPublicFoldersAllPublicFolders" in place of "olFolderInbox" but it does not recognize it.
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
推荐答案
请参见 https://msdn.microsoft.com/zh-CN/library/office/ff867877.aspx
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.("ABC Folder").Folders.("123 Folder").Folders.("Tat Monitor Folder")
删除默认项目"时出现错字
Typo when dropping the default "item"
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")
这篇关于在VBA中引用Outlook的“公用"文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!