1

I have four mailboxes ABC@123.com, DEF@123.com, GHI@123.com, and JKL@123.com.

The coding below goes to my tab named refTables gets the list of mailboxes. Goes to those INBOXES only.

I want to grab the emails from all subfolders as well.

Example subfolder names: InProgress, Pending Reply, and Ticket Submitted.

Private Function getEmails(emailAddress, folderName, destinationSheet)

'retrieves emails form outlook given address, folder, and destination sheet

Row = 2
For Each Folder In Outlook.Session.Folders
    If Folder.Name = emailAddress Then
        For Each subfolder In Folder.Folders
            If subfolder.Name = folderName Then
                For Each Item In subfolder.Items
                    If TypeName(Item) = "MailItem" And Item.MessageClass <> "IPM.Outlook.Recall" Then
                        Sheets(destinationSheet).Cells(Row, 1) = Item.ReceivedTime
                        Sheets(destinationSheet).Cells(Row, 2) = Round(Now() - Item.ReceivedTime, 0)
                        Sheets(destinationSheet).Cells(Row, 3) = Item.Categories
                        Sheets(destinationSheet).Cells(Row, 4) = Item.SenderName
                        Sheets(destinationSheet).Cells(Row, 5) = Item.Subject
                        Sheets(destinationSheet).Cells(Row, 6) = Item.TaskCompletedDate
                        Sheets(destinationSheet).Cells(Row, 7) = Folder.Name
                        Sheets(destinationSheet).Cells(Row, 8) = Item.LastModificationTime
                        Sheets(destinationSheet).Cells(Row, 9) = Round(Item.TaskCompletedDate - Item.ReceivedTime)
                         Row = Row + 1
                    End If
                Next
            End If
        Next
    End If
Next

End Function
Community
  • 1
  • 1
fireFly
  • 21
  • 4
  • Yes it is possible, but I think you will get better help if you reduce your code to a minimum. There is far too much code now to give you a good answer. – Sam Jan 16 '19 at 18:39
  • 1
    My apologies, its my first time. I thought if I added all of it it would help answer a few questions that may pop up. How about now? I could possibly shave it down a bit more. – fireFly Jan 16 '19 at 19:20
  • Much better! You are looking for a recursive algorithm. – Sam Jan 16 '19 at 19:49
  • For 2nd level folders see https://stackoverflow.com/questions/39225235/how-to-extract-emails-for-outlook-for-subfolders. For all folders see https://stackoverflow.com/questions/2272361/can-i-iterate-through-all-outlook-emails-in-a-folder-including-sub-folders – niton Apr 18 '19 at 20:14

0 Answers0