-
That's better.
Try (not sure about the depth of nesting of your folders in the Outlook folder tree):
[VBA]Sub Inb_GBDFSU()
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")
Cells.Delete
r = 1
'Build headings:
Range("A1
1") = Array("FoundIn", "RecdFrom/sentBy", "Subject", "Recd/SentTime")
FiveDaysAgo = Now - 1 'note it's now - 5*24 hours, not any time since midnight on a date 5 days ago.
'Change value if you want another folder:
Dim myFolders(1 To 4)
Set myFolders(1) = olNS.Folders("Mailbox - Satish gubbi").Folders("Inbox")
Set myFolders(2) = olNS.Folders("Mailbox - Satish gubbi").Folders("Sent Items")
Set myFolders(3) = olNS.Folders("Mailbox - Satish gubbi").Folders("Leased")
Set myFolders(4) = olNS.Folders("Mailbox - Satish gubbi").Folders("PRIME")
For Each item In myFolders
Set olFolder = item
For Each olItem In olFolder.Items
If TypeName(olItem) = "MailItem" Then
If olItem.ReceivedTime > FiveDaysAgo Then
r = r + 1
Cells(r, "A") = olFolder.Name
Cells(r, "B") = olItem.SenderName
Cells(r, "C") = olItem.Subject
Cells(r, "D") = olItem.SentOn
End If
End If
Next olItem
Next item
Columns.AutoFit
End Sub
[/VBA]
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules