![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi,
I'm trying to list all the folders in my mailbox using VBA. I know I need to perfom a recursive search but after nearly two day I've nearly given up the will to live! If anybody has the actual code (not a description of how to 'do it') this would be extremely helpful. Many, many thanks. Warren. |
#2
|
|||
|
|||
![]()
This is Outlook VBA code adapted from my forthcoming Outlook 2007 book. It puts a list in the Immediate window. You could adapt it to write the information to a file, a message, etc. Note that ProcessFolder is recursive.
Dim mlngItemCount As Long Dim mlngFolderCount As Long Dim mstrList As String Sub ListAllFolders() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objMsg As Outlook.MailItem mlngItemCount = 0 mlngFolderCount = 0 mstrList = "" Set objOL = Application Set objNS = objOL.Session For Each objFolder In objNS.Folders Call ProcessFolder(objFolder) mstrList = mstrList & vbCrLf Next Set objMsg = objOL.CreateItem(olMailItem) mstrList = mstrList & vbCrLf & _ "Total folders in Outlook = " & _ Format(mlngFolderCount, "###,###") & _ vbCrLf & "Total items in Outlook = " & _ Format(mlngItemCount, "###,###") objMsg.Body = mstrList objMsg.Display Set objOL = Nothing Set objNS = Nothing Set objFolder = Nothing End Sub Sub ProcessFolder(startFolder As Outlook.MAPIFolder) Dim objFolder As Outlook.MAPIFolder On Error Resume Next mstrList = mstrList & vbCrLf & startFolder.FolderPath & _ vbTab & startFolder.Items.Count mlngItemCount = mlngItemCount + startFolder.Items.Count mlngFolderCount = mlngFolderCount + 1 For Each objFolder In startFolder.Folders Call ProcessFolder(objFolder) Next Set objFolder = Nothing End Sub -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx wrote in message ps.com... Hi, I'm trying to list all the folders in my mailbox using VBA. I know I need to perfom a recursive search but after nearly two day I've nearly given up the will to live! If anybody has the actual code (not a description of how to 'do it') this would be extremely helpful. Many, many thanks. Warren. |
#3
|
|||
|
|||
![]()
Hi Sue,
Yesterday I was pulling my hair out with this problem. (You know how it is sometimes when no matter what you try, nothing seems to work!) What was really frustrating was not being able to find an example anywhere after many, many hours searching the net. Only if you have the time, is it possible you could post a copy that includes the option of which mailbox to search? For example "Mailbox - Joe bloggs\Inbox" etc Thank you Sue for all your kind help, merry Christmas! Warren. |
#4
|
|||
|
|||
![]()
Look at the Namespace.Folders collection:
Set objNS = objOL.Session Call ProcessFolder(objNS.Folders("Mailbox - Joe bloggs")) mstrList = mstrList & vbCrLf -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx wrote in message ups.com... Hi Sue, Yesterday I was pulling my hair out with this problem. (You know how it is sometimes when no matter what you try, nothing seems to work!) What was really frustrating was not being able to find an example anywhere after many, many hours searching the net. Only if you have the time, is it possible you could post a copy that includes the option of which mailbox to search? For example "Mailbox - Joe bloggs\Inbox" etc Thank you Sue for all your kind help, merry Christmas! Warren. |
#5
|
|||
|
|||
![]()
Thank you Sue, for all your help - Merry Christmas...!
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
HELP - Contacts Name Listing and Order | [email protected] | Outlook - Using Contacts | 7 | October 20th 06 11:05 PM |
OE6 listing messages | Andrew Kennard | Outlook Express | 3 | September 7th 06 09:32 PM |
email distribution listing | full.arm | Outlook - General Queries | 1 | August 12th 06 02:15 PM |
Need help listing another users folders | Rog | Outlook and VBA | 1 | July 19th 06 11:21 PM |
Listing all data files | [email protected] | Outlook and VBA | 2 | February 3rd 06 06:15 PM |