Я начал с
Sub GetEmailTesting()
Dim outlook_app As Outlook.Application
Dim namespace As Outlook.namespace
Set outlook_app = New Outlook.Application
Set namespace = outlook_app.GetNamespace("MAPI")
Dim main_folder As Outlook.MAPIFolder
Dim sub_folder1 As Outlook.MAPIFolder
Dim sub_folder2 As Outlook.MAPIFolder
Dim sub_folder3 As Outlook.MAPIFolder
On Error Resume Next
For Each main_folder In namespace.Folders
' code goes here
For Each sub_folder1 In main_folder.Folders
' code goes here
For Each sub_folder2 In sub_folder1.Folders
' code goes here
For Each sub_folder3 In sub_folder2.Folders
Dim rowNumber As Integer
rowNumber = 2
For Each obj_item In sub_folder3.Items
If obj_item.Class = olMail Then
Dim obj_mail As Outlook.MailItem
Set obj_mail = obj_item
Cells(rowNumber, 1) = obj_mail.SenderEmailAddress
Cells(rowNumber, 2) = obj_mail.To
Cells(rowNumber, 3) = obj_mail.Subject
Cells(rowNumber, 4) = obj_mail.ReceivedTime
End If
rowNumber = rowNumber + 1
Next
Next sub_folder3
Next sub_folder2
Next sub_folder1
Next main_folder
On Error GoTo 0
End Sub
Нужно ли вставлять это в каждый FOR EACH l oop (основная папка, подпапка 1, подпапка 2, подпапка 3 и т. Д. И т. Д. И т. Д.??
For Each obj_item In sub_folder3.Items
If obj_item.Class = olMail Then
Dim obj_mail As Outlook.MailItem
Set obj_mail = obj_item
Cells(rowNumber, 1) = obj_mail.SenderEmailAddress
Cells(rowNumber, 2) = obj_mail.To
Cells(rowNumber, 3) = obj_mail.Subject
Cells(rowNumber, 4) = obj_mail.ReceivedTime
End If
rowNumber = rowNumber + 1
Next