1

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.

Community
  • 1
  • 1
Selkie
  • 1,215
  • 1
  • 17
  • 34
  • 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 Mar 09 '17 at 21:12

2 Answers2

1

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
Inflorescence
  • 86
  • 1
  • 7
  • Thank you! I combined this with a vlookup and a named range in my excel sheet, so that users can enter in one-time what their folder is called. After doing that, they can then enter in their name into a vlookup, and it will pull what they've called their folder into the program. – Selkie Mar 09 '17 at 21:33
  • http://stackoverflow.com/a/23753758/6836407 seems to loop through every folder, which seems like an even better method! Unfortunately, for the life of me, I can't figure out what I need to dim efolder as. Tried MAPIFolder among other things, still nothing – Selkie Mar 09 '17 at 22:18
0

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).

Eric Legault
  • 5,706
  • 2
  • 22
  • 38