[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Dim RootFolder As String[/FONT]
[FONT=Courier New]Dim OlApp As Outlook.Application[/FONT]
[FONT=Courier New]Dim oMAPI As Outlook.Namespace[/FONT]
[FONT=Courier New]Dim oParentFolder As Outlook.MAPIFolder[/FONT]
[FONT=Courier New]Dim ws As Worksheet[/FONT]
[FONT=Courier New]Dim intTotalItems As Long[/FONT]
[FONT=Courier New]Dim intRowPointer As Long[/FONT]
[FONT=Courier New]Public Sub GetOutlookMail()[/FONT]
[FONT=Courier New] Dim dteTimer As Date[/FONT]
[FONT=Courier New] RootFolder = "[COLOR=red][B]Mailbox - SURNAME, Forename[/B][/COLOR]"[/FONT]
[FONT=Courier New] dteTimer = Now()[/FONT]
[FONT=Courier New] Set ws = ThisWorkbook.Sheets("[COLOR=red][B]Sheet1[/B][/COLOR]")[/FONT]
[FONT=Courier New] Set OlApp = CreateObject("Outlook.Application")[/FONT]
[FONT=Courier New] Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")[/FONT]
[FONT=Courier New] Set oParentFolder = oMAPI.Folders(RootFolder)[/FONT]
[FONT=Courier New] intTotalItems = 0[/FONT]
[FONT=Courier New] Call CountAllItems(oParentFolder)[/FONT]
[FONT=Courier New] ws.Columns("A:S").ClearContents[/FONT]
[FONT=Courier New] Call ColumnHeaders[/FONT]
[FONT=Courier New] intRowPointer = 2[/FONT]
[FONT=Courier New] Application.Cursor = xlWait[/FONT]
[FONT=Courier New] Call ProcessFolder(oParentFolder)[/FONT]
[FONT=Courier New] Application.Cursor = xlDefault[/FONT]
[FONT=Courier New] MsgBox "Done: " & CStr(intTotalItems) & " items (" & Format(dteTimer - Now(), "hh:nn:ss") & ")"[/FONT]
[FONT=Courier New] Set OlApp = Nothing[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]Private Sub CountAllItems(StartFolder As Outlook.MAPIFolder)[/FONT]
[FONT=Courier New] Dim uFolder As Outlook.MAPIFolder[/FONT]
[FONT=Courier New] Dim MailObject As Object[/FONT]
[FONT=Courier New] If StartFolder.DefaultItemType = 0 And StartFolder.FolderPath <> "\\" & RootFolder Then[/FONT]
[FONT=Courier New] intTotalItems = intTotalItems + StartFolder.Items.Count[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] If StartFolder.DefaultItemType = 0 Then[/FONT]
[FONT=Courier New] For Each uFolder In StartFolder.Folders[/FONT]
[FONT=Courier New] Call CountAllItems(uFolder)[/FONT]
[FONT=Courier New] Next uFolder[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] Set uFolder = Nothing[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]Private Sub ProcessFolder(StartFolder As Outlook.MAPIFolder)[/FONT]
[FONT=Courier New] Dim uFolder As Outlook.MAPIFolder[/FONT]
[FONT=Courier New] If StartFolder.DefaultItemType = 0 Then[/FONT]
[FONT=Courier New] Call ProcessItems(StartFolder, StartFolder.Items)[/FONT]
[FONT=Courier New] For Each uFolder In StartFolder.Folders[/FONT]
[FONT=Courier New] Call ProcessFolder(uFolder)[/FONT]
[FONT=Courier New] Next uFolder[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] Set uFolder = Nothing[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]Private Sub ProcessItems(CurrentFolder As Outlook.MAPIFolder, Collection As Outlook.Items)[/FONT]
[FONT=Courier New] Dim MailObject As Object[/FONT]
[FONT=Courier New] Dim intAttachment As Integer[/FONT]
[FONT=Courier New] For Each MailObject In Collection[/FONT]
[FONT=Courier New] DoEvents[/FONT]
[FONT=Courier New] If TypeOf MailObject Is MailItem Then[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 1) = MailObject.SentOn[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 2) = MailObject.SenderName[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 3) = MailObject.SenderEmailAddress[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 4) = MailObject.SentOnBehalfOfName[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 5) = MailObject.To[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 6) = MailObject.CC[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 7) = MailObject.BCC[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 8) = MailObject.ReceivedByName[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 9) = MailObject.ReceivedOnBehalfOfName[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 10) = MailObject.ReplyRecipientNames[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 11) = MailObject.Subject[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 12) = MailObject.Body[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 13) = MailObject.HTMLBody[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 14) = MailObject.Importance[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 15) = MailObject.Attachments.Count[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 16) = ""[/FONT]
[FONT=Courier New] For intAttachment = 1 To MailObject.Attachments.Count[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 16) = ws.Cells(intRowPointer, 16) & ";" & MailObject.Attachments(intAttachment).Filename[/FONT]
[FONT=Courier New][COLOR=green] ' we may want to save some or all of the attachments[/COLOR][/FONT]
[FONT=Courier New][COLOR=green] ' MailObject.Attachments(intAttachment).SaveAsFile "C:\Temp\" & MailObject.Attachments(intAttachment).FileName[/COLOR][/FONT]
[FONT=Courier New] Next intAttachment[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 16) = Mid(ws.Cells(intRowPointer, 16), 2) ' remove leading semicolon[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 17) = CurrentFolder.FolderPath[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 18) = CurrentFolder.Name[/FONT]
[FONT=Courier New] If MailObject.UnRead Then[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 19) = "N"[/FONT]
[FONT=Courier New] Else[/FONT]
[FONT=Courier New] ws.Cells(intRowPointer, 19) = "Y"[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] intRowPointer = intRowPointer + 1[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] Next MailObject[/FONT]
[FONT=Courier New] Set MailObject = Nothing[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]Private Sub ColumnHeaders()[/FONT]
[FONT=Courier New] Dim ColumnHeads As Variant[/FONT]
[FONT=Courier New] ColumnHeads = Array("SenderName", "SenderEmailAddress", "SentOnBehalfOfName", "To", "CC", _[/FONT]
[FONT=Courier New] "BCC", "ReceivedByName", "ReceivedOnBehalfOfName", "ReplyRecipientNames", "Subject", _[/FONT]
[FONT=Courier New] "SentOn", "Body", "HTMLBody", "Importance", "AttachmentsCount", "Attachments", _[/FONT]
[FONT=Courier New] "FolderPath", "FolderName", "Read")[/FONT]
[FONT=Courier New] ws.Range("A1").Resize(1, UBound(ColumnHeads) + 1) = ColumnHeads[/FONT]
[FONT=Courier New] Rows("2").Select[/FONT]
[FONT=Courier New] With ActiveWindow[/FONT]
[FONT=Courier New] .SplitColumn = 0[/FONT]
[FONT=Courier New] .SplitRow = 1[/FONT]
[FONT=Courier New] End With[/FONT]
[FONT=Courier New] ActiveWindow.FreezePanes = True[/FONT]
[FONT=Courier New] ws.Rows("1").Font.Bold = True[/FONT]
[FONT=Courier New]End Sub[/FONT]