Get Items Collection from default Outlook folders

If you were directed to this page, it means that you need to return the Items collection from one of Outlook's default folders. Here is the code:

Function GetItems(olNS As Outlook.NameSpace, folder As OlDefaultFolders) _
    As Outlook.Items
  Set GetItems = olNS.GetDefaultFolder(folder).Items
End Function

Function GetOutlookApp() As Outlook.Application
' returns reference to native Application object
  Set GetOutlookApp = Outlook.Application
End Function

Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
  Set GetNS = app.GetNamespace("MAPI")
End Function

This code should be used as follows:

Dim olApp As Outlook.Application

Set olApp = Outlook.Application
' get all Inbox items
Set Items = GetItems(GetNS(olApp), olFolderInbox)

Using this code you can return the Items collection for the most popular default folders, and iterate through the collection. For example:

  • Calendar – olFolderCalendar
  • Contacts – olFolderContacts
  • Deleted Items – olFolderDeletedItems
  • Drafts – olFolderDrafts
  • Inbox – olFolderInbox
  • Journal – olFolderJournal
  • Junk – olFolderJunk
  • Notes – olFolderNotes
  • Sent Mail – olFolderSentMail
  • Tasks – olFolderTasks

For working examples, see

Site last updated: May 17, 2012

Random Data Generator