本文介绍了从根文件夹检索共享邮箱邮件到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个代码,我认为应该从共享邮箱文件夹中提取所有邮件项目.
I have a code currently which I think should pull all mail items from a shared mailbox folder.
我知道从根目录循环遍历共享邮箱中的所有文件夹都存在一些问题.
I know there is some problem in looping all folders in shared mailbox from root.
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Outlook.Namespace
Dim olShareName As Outlook.Recipient
Dim Folder As MAPIFolder
Dim eFolder As Outlook.Folder
Dim olItems As Outlook.Items
Dim OutlookMail As Variant
Dim arrResults() As Variant
Dim ItemCount As Long
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set olShareName = OutlookNamespace.CreateRecipient("[email protected]")
For Each eFolder In OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox).Folders
Set Folder = OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox).Folders(eFolder.Name)
Set olItems = Folder.Items.Restrict("[ReceivedTime] >= '" & Range("From_date").Value & "' and [ReceivedTime] <= '" & Range("to_date").Value & "'")
If olItems.Count > 0 Then
ReDim arrResults(1 To olItems.Count, 1 To 5)
ItemCount = 0
For Each OutlookMail In olItems
ItemCount = ItemCount + 1
arrResults(ItemCount, 1) = OutlookMail.Subject
arrResults(ItemCount, 2) = OutlookMail.ReceivedTime
arrResults(ItemCount, 3) = OutlookMail.SenderName
arrResults(ItemCount, 4) = OutlookMail.Size
arrResults(ItemCount, 5) = OutlookMail.Categories
Next OutlookMail
Worksheets("import").Range("A5").Resize(UBound(arrResults, 1), 5) = arrResults
Else
MsgBox "No items found!", vbExclamation
End If
Set olItems = Nothing
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set olShareName = Nothing
Set OutlookApp = Nothing
Next eFolder
推荐答案
请记住,默认情况下,Outlook在主邮箱的OST文件中缓存共享文件夹.子文件夹不被缓存.尝试在"Exchange帐户属性"对话框中禁用共享文件夹缓存.
Keep in mind that by default Outlook caches shared folders in the primary mailbox's OST file. Subfolders are not cached. Try to disable the shared folder caching in the Exchange account properties dialog.
这篇关于从根文件夹检索共享邮箱邮件到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!