Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 9 of 9

Thread: Export List Of All Outlook Folders

  1. #1
    Join Date
    15th November 2004
    Location
    Edinburgh, Scotland
    Posts
    94

    Export List Of All Outlook Folders

    Hi all,

    (Outlook) Folders within folders within folders.

    I'm trying to autogenerate a list (into Excel) of the folderpaths of all the folders within my Outlook.

    What I have so far is this:

    VB:
    Public Sub ListOutlookFolders() 
         
        Dim olApp As Outlook.Application 
        Dim olNamespace As Outlook.Namespace 
        Dim olFolder As Outlook.Folders 
        Dim objFolder As Outlook.MAPIFolder 
         
        Dim rngOut As Range 
         
        Set olApp = New Outlook.Application 
        Set olNamespace = olApp.GetNamespace("MAPI") 
        Set olFolder = olNamespace.Folders 
         
        Set rngOut = Range("A1") 
         ' Personal Folders
         ' Inbox
         
        For Each objFolder In olFolder 
            On Error Resume Next 
            rngOut = objFolder.FolderPath 
            Set rngOut = rngOut.Offset(1, 0) 
        Next 
         
        Set rngOut = Nothing 
        Set olNamespace = Nothing 
        Set olApp = Nothing 
         
    End Sub 
    
    
    which all works great at the first level.

    My question is how do I now make this code loop through all the folders within folders etc...?

    Many thanks,
    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  2. #2
    Join Date
    15th November 2004
    Location
    Edinburgh, Scotland
    Posts
    94

    Re: Export List Of All Outlook Folders

    Anybody able to help with this??

    All thoughts appreciated.
    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  3. #3
    Join Date
    15th November 2004
    Location
    Edinburgh, Scotland
    Posts
    94

    Re: Export List Of All Outlook Folders

    Ok - sorry I couldn't get any help, but have slogged through it myself.

    For the rest of you who might be asking yourselves the same question, here's the code.

    Please note this only works in Office 2003 as the FolderPath method was only available then. If you'd like to see how it works in an earlier version and you have access to Books24x7.com then follow this link

    Don't know why the link function is not working. Here is the full path:

    http://www.books24x7.com/book/id_436...1288&rowid=589

    For those without access to Books24x7.com the details of the book are below:

    Microsoft Outlook Programming: Jumpstart for Administrators, Power Users, and Developers
    by Sue Mosher (ISBN:9781555582869)
    Chapter 12 - Working with Stores and Folders
    Digital Press 2003
    Section 12.4.5 Walking the folder tree to get any folder

    or take a look at her excellent site

    VB:
     'Variable to keep an overall row number
    Public RowNo As Integer 
     
    Private Sub CommandButton1_Click() 
         
         'Used to keep track of the number of folders
        Dim lCountOfFound As Long 
         
         'The output range
        Dim rngPath As Range 
         
         'Starting the row number off
        RowNo = 1 
         
         'Call this sub procedure
        WalkFolders 
         
    End Sub 
     
    Sub WalkFolders() 
         
        Dim olApp As Outlook.Application 
        Dim olSession As Outlook.Namespace 
        Dim olStartFolder As Outlook.MAPIFolder 
         
        lCountOfFound = 0 
         
        Set olApp = New Outlook.Application 
        Set olSession = olApp.GetNamespace("MAPI") 
         
         ' Allow the user to pick the folder in which to start the search.
         'or use  GetDefaultFolder(olFolderInbox).Parent instead of the PickFolder
        Set olStartFolder = olSession.PickFolder 
         
         ' Check to make sure user didn't cancel PickFolder dialog.
        If Not (olStartFolder Is Nothing) Then 
             ' Start the search process.
            ProcessFolder olStartFolder 
        End If 
         
    End Sub 
     
    Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder) 
         
        Set rngPath = Cells(RowNo, 1) 
         
        Dim i As Long 
        Dim olNewFolder As Outlook.MAPIFolder 
         ' late bind this object variable, since it could be various item types
        Dim olTempFolder As Outlook.MAPIFolder 
        Dim olTempFolderPath As String 
         
         ' Loop through the items in the current folder.
         ' Looping through backwards in case items are to be deleted,
         ' as this is the proper way to delete items in a collection.
        For i = CurrentFolder.Folders.Count To 1 Step -1 
             
            Set olTempFolder = CurrentFolder.Folders(i) 
             
             'Puts File Path into Excel here
            olTempFolderPath = olTempFolder.FolderPath 
            Cells(RowNo, 1) = olTempFolderPath 
             
            RowNo = RowNo + 1 
             
            lCountOfFound = lCountOfFound + 1 
             
        Next 
         
         ' Loop through and search each subfolder of the current folder.
        For Each olNewFolder In CurrentFolder.Folders 
             
             'Don't need to process the Deleted Items folder
            If olNewFolder.Name <> "Deleted Items" Then 
                ProcessFolder olNewFolder 
            End If 
             
        Next 
         
    End Sub 
    
    
    Cheers,
    Last edited by grint; September 4th, 2007 at 00:22.
    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  4. #4
    Join Date
    30th September 2008
    Posts
    2

    Re: Export List Of All Outlook Folders

    I know this is very old but I really needed to say thank you for that code.

    Have a nice day.

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    15th November 2004
    Location
    Edinburgh, Scotland
    Posts
    94

    Re: Export List Of All Outlook Folders

    Quote Originally Posted by Mikoli View Post
    I know this is very old but I really needed to say thank you for that code.

    Have a nice day.
    Mikoli - glad I could help...
    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  6. #6
    Join Date
    8th May 2012
    Posts
    2

    Re: Export List Of All Outlook Folders

    Quote Originally Posted by grint View Post
    Mikoli - glad I could help...
    Hope your still around as I too need this code to work and in trying to run it I get a compile error.

    Compile Error
    Sub or Function not defined

    Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)

    Set rngPath = Cells(RowNo, 1)

    Excel Video Tutorials / Excel Dashboards Reports


  7. #7
    Join Date
    8th May 2012
    Posts
    2

    Re: Export List Of All Outlook Folders

    Found another solution which works:

    http://www.msoutlook.info/question/515

    Excel Video Tutorials / Excel Dashboards Reports


  8. #8
    Join Date
    31st July 2012
    Posts
    1

    Re: Export List Of All Outlook Folders

    grint, nice to see your solution & thanks for sharing it after the work you invested in it!
    FYI, looking for a solution too, I bumped into one using a vbs script. Maybe this is handy to know too:
    http://help.wugnet.com/office/print-...ict953144.html
    Take care!

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    14th June 2013
    Posts
    1

    Re: Export List Of All Outlook Folders

    Great post! Thank you!

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Get Contact Details From Outlook Public Folders
    By malcomio in forum Excel and/or Email Help
    Replies: 2
    Last Post: June 19th, 2008, 17:14
  2. Attachments From Personal Folders In Outlook
    By facruz in forum Excel and/or Email Help
    Replies: 1
    Last Post: September 27th, 2006, 03:16
  3. Scanning E-mails in Outlook Sub-Folders from xl VBA
    By IanDunnett in forum EXCEL HELP
    Replies: 1
    Last Post: April 27th, 2006, 17:55
  4. Change Outlook Folders in VBA
    By tdrexler in forum Excel and/or Email Help
    Replies: 2
    Last Post: September 16th, 2005, 02:44
  5. Search all folders/subfolders in outlook
    By bvg in forum Excel and/or Email Help
    Replies: 1
    Last Post: March 12th, 2005, 00:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno