Below code will extract data from Outlook to Excel, its working fine, I need to alter this code to extract only current + last 5 days data from outlook.
in other words, there should be message box which displays the date criteria "From Date" and "To Date" to extract the details from Outlook
And also each line data should show from which folder the data has been extracted (if it extracted from "Inbox", "Sent Items")
kindly help me in this regard
[vba]
Sub Inb()
Dim appOutlook As Object
Dim olNS As Object
Dim olFolder As Object
Dim olItem As Object
Dim r As Long
'Get/create Outlook Application
On Error Resume Next
Set appOutlook = GetObject(, "Outlook.Application")
If appOutlook Is Nothing Then
Set appOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set olNS = appOutlook.GetNamespace("MAPI")
'Change value if you want another folder:
Set olFolder = olNS.Folders(("Mailbox - Satish Gubbi ")).Folders("Inbox")
Cells.Delete
r = 1
'Build headings:
Range("A1:C1") = Array("ReceivedFrom", "Subject", "ReceivedTime")
For Each olItem In olFolder.Items
If TypeName(olItem) = "MailItem" Then
r = r + 1
Cells(r, "A") = olItem.SenderEmailAddress
Cells(r, "B") = olItem.Subject
Cells(r, "C") = olItem.SentOn
End If
Next olItem
Columns.AutoFit
End Sub
[/vba]