Folders & Subfolders

M

Marvin Buzz

I am writing in Visual Basic, not VBA. I can write the code to identify all
of the subfolders in Outlook, but do not know how to program for the
subfolders of the subfolders...subfolders to any possible depth of subfolders.

Any samples or guidance would be very much appreciated.

Thanks in advance.
 
S

Sue Mosher [MVP]

Each Folder in Outlook 2007 or MAPIFolder in earlier versions has a Folders
collection containing all its subfolders. Each subfolder in a Folders
collection has a unique name, so you can return any subfolder with an
expression like this:

myParentFolder.Folders("Name of subfolder")

The code sample at http://www.outlookcode.com/codedetail.aspx?id=628 shows
how to process all the folders below a given starting folder.
 
A

Alan Moseley

You need to write a sub or function that is recursively called by itself.
For example:-

Public Sub ProcessAllFolders()
Dim fld As MAPIFolder
For Each fld In Application.GetNamespace("MAPI").Folders
Call ProcessFolder(fld)
Next fld
End Sub

Public Sub ProcessFolder(ByRef fld As MAPIFolder)
Dim subfld As MAPIFolder
'Do Something here
For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub
 
A

Alan Moseley

Firstly add a reference to Outlook within your project. Secondly import the
namespace before the beginning of your class, ie:-

Imports Microsoft.Office.Interop.Outlook
 
M

Marvin Buzz

Thanks for your response. I figured out how to add a reference, but I get an
error on the IMPORTS statement that I copied from your prior response. It
says sub or function not defined. I do not understand what you mean by my
"class". The code I am trying to execute is in a form run from VB.

Marvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top