Option Explicit
Public Sub Test()
Dim folder1 As Outlook.Folder
Dim folder2 As Outlook.Folder
Set folder1 = ...
Set folder2 = ...
Dim colAllMailItems As VBA.Collection
Call AddMailItemsFromFolder(folder1, colAllMailItems)
Call AddMailItemsFromFolder(folder2, colAllMailItems)
Dim objMailItem As Outlook.MailItem
For Each objMailItem In colAllMailItems
' folder-name, mail-subject
Debug.Print objMailItem.Parent.Name, objMailItem.Subject
Next
End Sub
Public Sub AddMailItemsFromFolder(ByVal Folder As Outlook.Folder, ByRef MailItemCollection As VBA.Collection)
If MailItemCollection Is Nothing Then
Set MailItemCollection = New VBA.Collection
End If
Dim objItem As Object
For Each objItem In Folder.Items
If TypeOf objItem Is Outlook.MailItem Then
Call MailItemCollection.Add(objItem)
End If
Next
End Sub
|