I wish to create a pivot of the message receipts in an Outlook folder. I am coding in Excel so that the code can be run by anyone in the department without adding code to their Outlook profile.
Using code that I have already got working for checking Categories in another folder I have modified it to check message receipts:
The problem is that I am now checking ReportItems rather than MessageItems so .ReceivedByName and .SenderName do not work.
Searching for a solution I found that the use of CDO or Redemption seems to be the answer but, as all example code is Outlook centric, I can't fathom where to start.
Perhaps you guys can give me a pointer
Using code that I have already got working for checking Categories in another folder I have modified it to check message receipts:
Code:
Dim olApp As Object, olNS As Object, olMail As Object, eFldr As Object
Dim LstColumn As Integer, Arr() As Variant, SrtRng As Range, slac As Date
Dim rngArray As Variant, strSorted As String
' Set the reference to outlook or create one
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")
' Set the reference to the oulook MAPI namespace
Set olNS = olApp.GetNamespace("MAPI")
' Define the generic Mailbox name
MBG = "Mailbox - Sales Support"
Set eFldr = olNS.Folders(MBG).Folders("Inbox").Folders("Read Receipts")
Application.StatusBar = "Removing previous data..."
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Worksheets("Data").Cells.Delete
Worksheets("Collect data").Activate
Application.StatusBar = "Gathering data from Outlook..."
Worksheets("Data").Activate
With Range("F:F")
.ColumnWidth = 18
.NumberFormat = "dd/mm/yyyy hh:mm:ss"
End With
Range("A1") = MBG
Range("E1") = "Ran"
Range("F1") = Now()
Range("A2") = "Total Items"
Range("B2") = eFldr.items.Count
Range("A3") = "Total Unread items"
Range("B3") = eFldr.UnReadItemCount
Range("A5") = "From"
Range("B5") = "Subject"
Range("C5") = "Received"
Range("A1:A3").Font.Bold = True
Range("E1:E2").Font.Bold = True
Range("A5:K5").Font.Bold = True
' Cycle through the emails in the generic mailbox, Exception folder
rn = 6
For Each omessage In eFldr.items
Application.StatusBar = "Reading message " & rn - 5 & " of " & eFldr.items.Count
With omessage
' Range("A" & rn) = .ReceivedByName
' Range("A" & rn) = .SenderName
Range("B" & rn) = .Subject
End With
rn = rn + 1
DoEvents
Next omessage
'Create Pivot Table
Application.StatusBar = "Creating pivot table..."
Application.DisplayAlerts = False
Worksheets("Pivot").Delete
Application.DisplayAlerts = True
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
sData = Selection.Address
Sheets.Add
nSheet = "Pivot"
ActiveSheet.Name = nSheet
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=sData, Version:=xlPivotTableVersion10).CreatePivotTable TableDestination:=nSheet & "!R3C1", DefaultVersion:=xlPivotTableVersion10
pName = "PivotTable1"
ActiveSheet.PivotTables(1).Name = pName
Cells(3, 1).Select
Set pt = ActiveSheet.PivotTables(pName)
pt.AddDataField pt.PivotFields("Subject"), "Count of Subject", xlCount
pt.PivotFields("Subject").Orientation = xlRowField
Application.StatusBar = "Complete"
Set olApp = Nothing
Set olNS = Nothing
Set olMail = Nothing
Set eFldr = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.StatusBar = ""
Searching for a solution I found that the use of CDO or Redemption seems to be the answer but, as all example code is Outlook centric, I can't fathom where to start.
Perhaps you guys can give me a pointer
