EXCEL VBA代码来检索sharedmailbox从根文件夹到子文件夹的所有邮件 [英] EXCEL VBA code to retrieve sharedmailbox all mails from root folders to subfolders
本文介绍了EXCEL VBA代码来检索sharedmailbox从根文件夹到子文件夹的所有邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个代码,我认为它应该仅从默认文件夹中提取所有指定的邮件项目。
I have a code currently which I think should pull all mail items specified from only default folder.
它无法正常工作。我知道从根循环共享邮箱中的所有文件夹时存在一些问题。如何解决?
It's not working as I expected. I know there is some problem in looping all folders in shared mail box from root. How can fix it?
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("example@example.com")
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
推荐答案
请记住,默认t 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.
这篇关于EXCEL VBA代码来检索sharedmailbox从根文件夹到子文件夹的所有邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文