PDA

View Full Version : Solved: Looping through Inbox to find all Sub Folders



Sherrie
11-03-2011, 11:01 PM
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!

Charlize
11-04-2011, 06:40 AM
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 SubCharlize

JP2112
11-04-2011, 10:01 AM
Do you think the code might need to be recursive?

Charlize
11-04-2011, 11:48 AM
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

Sherrie
11-04-2011, 03:14 PM
Thank you both for the replies! :thumb

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

Sherrie
11-06-2011, 01:37 AM
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!

JP2112
11-07-2011, 10:25 AM
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?

Sherrie
11-07-2011, 07:04 PM
Nope, I didn't.

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

Sherrie
11-09-2011, 02:41 AM
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! :giggle

Thanks for all the help!