Hi all,
I am currently struggling to find a way to search Outlook to find a folder.
I the following code so far:
Dim oitem As Outlook.MailItem
Dim ol As Outlook.Application
Dim olns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim j As Long
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set oinbox = olns.GetDefaultFolder(olFolderInbox) 'select's the inbox, but i have others
Set oinbox = oinbox.Folders("Agency") 'this the subfolfer
Application.DisplayAlerts = False
oinbox.Items.Sort "[ReceivedTime]", True
j = 2
For Each oitem In oinbox.Items ' loop outlook emails
ThisWorkbook.Sheets(1).Range("a" & j).Value = oitem.SenderName
ThisWorkbook.Sheets(1).Range("b" & j).Value = oitem.Subject
ThisWorkbook.Sheets(1).Range("c" & j).Value = oitem.ReceivedTime
ThisWorkbook.Sheets(1).Range("d" & j).Value = oitem.Categories
Next
Set oinbox = Nothing
Set olns = Nothing
Set ol = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = False
End Sub
The following are defaults that I am aware of:
'olFolderDeletedItems = 3
'olFolderOutbox = 4
'olFolderSentMail = 5
'olFolderInbox = 6
'olFolderCalendar = 9
'olFolderContacts = 10
'olFolderJournal = 11
'olFolderNotes = 12
'olFolderTasks = 13
'olFolderDrafts = 16
'olFolderJunk = 23
Thank you for looking
Vj