Consulting

Results 1 to 9 of 9

Thread: Solved: Looping through Inbox to find all Sub Folders

  1. #1
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location

    Solved: Looping through Inbox to find all Sub Folders

    Hi all,

    Can someone point me in the right direction of finding some VBA code to look through all the sub folders in the Inbox?

    Any help will be greatly appreciated!

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    [VBA]Sub Loop_folders_of_inbox()
    Dim ns As Outlook.NameSpace
    Dim myfolder As Outlook.Folder
    Dim mysubfolder As Outlook.Folder
    Set ns = Application.GetNamespace("MAPI")
    'Get the default inboxfolder
    Set myfolder = ns.GetDefaultFolder(olFolderInbox)
    'Loop through each folder and display name of the folder
    For Each mysubfolder In myfolder.Folders
    MsgBox mysubfolder.Name
    Next mysubfolder
    End Sub[/VBA]Charlize

  3. #3
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Do you think the code might need to be recursive?
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Well, I just did a wild guess because the OP wanted to loop through all the subfolders of the inboxfolder. I've omitted the looping through each item in those folders (and the moving, saving ... --- thought I saw another thread about that ---) to keep it understandable.

    Charlize

  5. #5
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location
    Thank you both for the replies!

    I've kinda got the snippets of code that I want to execute for each folder.

    Will try them together, and I sure know where to get help if I get into more strife, which I'm sure I will being such a novice at this! LOL

  6. #6
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location

    Can't seem to make this code work

    Hi, have tried using this code to loop through but it's not giving me a msg with all the subfolders names.

    I copied and pasted it into a macro and tried running the macro.

    Thanks again!

  7. #7
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    The code worked for me, so I'm afraid you'll need to be more specific. Did you try pressing F8 to step through the code?
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  8. #8
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location
    Nope, I didn't.

    Will try then when I get home and post an update.

  9. #9
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location
    I just figured out my problem! It was looping through the Inbox in My Personal Folders instead of the other account.

    Feel really silly now!

    Thanks for all the help!

Posting Permissions

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