1
votes

I've done some searching, and I can't quite find a definitive yes or no answer anywhere.

I'm writing a program that will, when you press a button in Excel, go to outlook, scan it for particular e-mails, then download the attachments in a certain way. Ok, very doable, lots of guides out there how to do it.

What I can't find is if it's doable on a variable folder structure. As in, everyone who's going to use this program has their outlook folders set up in a different way. Is there a way to be able to find the emails I want wherever they're hiding, without creating a unique path per person who might use this program, and without making every person who might use this email set up their inbox in the same way?

The email name will be the same every day, with a date appended, which is how I plan to find the email in the first place.

2
I think this might work - if I create a manual location for people to post their particular folderpath in, and then look for that folderpath when I'm running the function?Selkie

2 Answers

1
votes

If the folders you're looking for all have something in common, you might be able to use a For Each loop and a conditional:

For each folder in myFolder.Folders
    If folder.Name = "Surprise Party" then
         'Run code
    End If
Next folder
0
votes

Looping through a dynamic number of folders to find a specific item is not the best option performance wise. A better approach is to use the AdvancedSearch method. You can specify multiple folders and include subfolders and then iterate through a single collection (.Results).