Browse Outlook (Mail) Folders?

  • Thread starter Thread starter MatrimCauthon
  • Start date Start date
M

MatrimCauthon

Hello,

how is it possible to retrieve all the mail folders and then get th
items they are holding?

I want to go over every mail (in preselected folders).


So I need to set up the folders which should be scanned.

And than get all the (mail)items in it.

How can I achieve this?

Thanks in advance,

Mat
 
Use this code in a module which will loop through all of your Personal
Folders (.pst files) and every folder in the hierarchy that is a mail
folder, and return per loop the number of items in that folder. If you want
access to individual messages, grab it from the myFolder.Items collection
for the current folder. You can check the arrPath array to see all of the
folders that have been scanned.

Option Explicit
Dim I As Integer
Dim arrPath() As String
Dim myApp As Outlook.Application
Dim myNs As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim colFolders As Folders
Dim colFolders2 As Folders

Sub Run()
Set myApp = New Outlook.Application
Set myNs = myApp.GetNamespace("MAPI")
Set colFolders = myNs.Folders
RecurseMailFolders colFolders
End Sub

Sub RecurseMailFolders(objTheseFolders As Outlook.Folders)
Dim lngItemCount As Long
For Each myFolder In objTheseFolders
' Debug.Print myFolder.Name
If myFolder.DefaultItemType = olMailItem Then
ReDim Preserve arrPath(I + 1)
arrPath(I) = myFolder.FolderPath
lngItemCount = myFolder.Items.Count
Set colFolders2 = myFolder.Folders
I = I + 1
RecurseMailFolders colFolders2
End If
Next
End Sub
 
Thank you,

it works the way I can get all the folder names.
(There is no inbuilt way that I can have the list like a directory Tre
in explorer, right?
Im feeding the folders in a TreeView structure for now)

But anyway, thank you again.
 
You're welcome. The closest thing to having the list in a directory tree is
the NameSpace.PickFolder, but it is not a designable form. I'm sure glad we
have that method though!
 
Back
Top