Inbox Sub Folders

I

IanPike

I am new to this game so this could well be a stupid question, (so lets
get the Dad's Army "Stupid Boy Pike" gags out of the way first you need
to be a Brit to understand that)

I have a routine that goes through the INBOX and saves away any
attachments to disk and then deletes them from the mail, to reduce the
PST file size. However i have sub folders below my INBOX and also sub
sub folders, how can i get a list off all sub folders of the INBOX and
work my way down through them?

Thanks in advance for any help

Regards

Ian Pike
Magellan Aerospace UK Ltd
 
S

Sue Mosher [MVP]

Every folder has two collections that comprise its contents. The Items collection holds the mail messages and other individual Outlook items, while the Folders collection holds the subfolders, each of which in turn has its own Items collection.

So, your code needs to iterate not just the Items collection, but also the Folders collection. Since you can't know how many levels of subfolders might be present, you use a technique called recursion in which a procedure calls itself repeatedly until it runs out of things to process. It might look something like this:

Sub ProcessFolder(MyFolder)
For Each objItem in MyFolder.Items
' do your item processing
Next
For Each objFolder in MyFolder.Folders
Call ProcessFolder(objFolder)
Next
End Sub

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

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