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!
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!
[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
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
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
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
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!
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
Nope, I didn't.
Will try then when I get home and post an update.
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!