+ Reply to Thread
Results 1 to 6 of 6

Thread: Loop through folders in Outlook

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Loop through folders in Outlook

    I'm trying to write a macro in Outlook that will loop through all the folders until it finds one with a specific name. But, I can't seem to figure out the logic to ensure it keeps looping until it gets to the end of each branch structure. For example, the folder could be like this:-
    Code:
    Inbox
       - Some Folder
            - Folder I want
    
    or like this:-
    Code:
    Inbox
       - Folder I want
    
    Basically, I just need to know the logic to keep a For Each or While loop going all the way down a tree structure, which I don't know the possible length of.

    Any ideas?

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I have an example someplace that I can dig out later -- but think RECURSION.

    1. For each folder, get a list of it's subfolders
    2. For each folder in that list, do 1.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Wolffy View Post
    I have an example someplace that I can dig out later -- but think RECURSION.

    1. For each folder, get a list of it's subfolders
    2. For each folder in that list, do 1.
    Yeah, but then how many times do you do it? It would be based on individual's Outlook so they could place the folder anywhere in the hierarchy. So, if you did it, 4 times and the folder you wanted was 5 levels down, you wouldn't get it. I was thinking there was a way of doing it without knowing how far down to go.

    I think I may have come up with a way of the the mail server handling this, so maybe hang fire for the moment...

    Thanks though Wolffy.

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Look at my recursive menu function in the .net code samples forum. Notice how I call it there. I never know how many levels down it goes, it handles it automagically.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    Look at my recursive menu function in the .net code samples forum. Notice how I call it there. I never know how many levels down it goes, it handles it automagically.
    Will do J...

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I got the mail server to handle it in the end, thank god. Offers various event handlers, one of which is OnFailedMessage, so managed to do everything I needed in this event handler.

    Not sure I fancied having to rely on a macro in Outlook to sort it...

+ Reply to Thread

Similar Threads

  1. Mail to link, open outlook form?
    By Rebelle in forum JavaScript Programming
    Replies: 14
    Last Post: June 9th, 2010, 08:40 AM
  2. Outlook 2007 Junk Email Filter
    By richyrich in forum Microsoft Office
    Replies: 5
    Last Post: March 5th, 2010, 05:11 PM
  3. Outlook 2007 Crashing
    By richyrich in forum Microsoft Windows
    Replies: 1
    Last Post: January 25th, 2010, 05:54 AM
  4. Making windows .exe call available in all folders
    By richyrich in forum Microsoft Windows
    Replies: 3
    Last Post: October 22nd, 2009, 11:24 AM
  5. href in email or outlook issue?
    By Rebelle in forum ASP Development
    Replies: 3
    Last Post: February 18th, 2009, 11:43 AM

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

SEO by vBSEO