I want to fetch all the Outlook inbox emails into an Excel sheet with additional columns having the data like This mail was replied on or This mail was forwarded to
Here is the code that I have done so far
Dim Folder As Outlook.MAPIFolder
Dim iRow As Integer
MailBoxName = 'Mailbox Name Goes Here
Pst_Folder_Name = "Inbox"
Set Folder = Outlook.Session.PickFolder 'Folders(MailBoxName).Folders(Pst_Folder_Name)
If Folder = "" Then
MsgBox "Invalid Data in Input"
GoTo end_lbl1:
End If
Folder.Items.Sort "[ReceivedTime]", False
LimitDateTimeValue = 'Date Limit
CellNo = 2
For iRow = 1 To Folder.Items.Count
On Error Resume Next
If Folder.Items.Item(iRow).ReceivedTime > LimitDateTimeValue Then
'CellNo = 2
On Error Resume Next
ThisWorkbook.Sheets("Inbox").Range("A2").Select
FullSubjectLine = Folder.Items.Item(iRow).Subject
If InStr(1, FullSubjectLine, "FE:", vbTextCompare) > 0 Or InStr(1, FullSubjectLine, "FW:", vbTextCompare) > 0 Or InStr(1, FullSubjectLine, "RE:", vbTextCompare) Then
FilteredSubjectLine = Mid(FullSubjectLine, 5)
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 2) = FilteredSubjectLine
Else
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 2) = Folder.Items.Item(iRow).Subject
End If
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 4) = Left(Folder.Items.Item(iRow).Body, 1024)
If Folder.Items.Item(iRow).UnRead Then
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 6) = "UnRead"
Else
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 6) = "Read"
End If
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 1) = Folder.Items.Item(iRow).SenderName
ThisWorkbook.Sheets("Inbox").Cells(CellNo, 3) = Folder.Items.Item(iRow).ReceivedTime
CellNo = CellNo + 1
End If
Next iRow