For Each Next routine

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have a number of folders and I want a procedure to open each folder in the designated path and run some code if there are any files in the folder.

I am a little stuck with what code I need to do this.


Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I was under the impression that I need to use FileSystemObject in order to do what I want. Is that not the case?
 
Upvote 0
You don't need to use FileSystemObject but it is one method.

And if you are using Excel 2007 which Microsoft has dropped Application.FileSearch from then it might be the best method.

There are other methods though. eg Dir
 
Upvote 0
Which is the best method?

I am not that familiar with 'Dir' method (or FSO, hence this post!!!)
 
Upvote 0
I think it's really a personal preference thing.

I always use(d) the Application.FileSearch method, but sometimes it would be a bit quirky.

That's apparently why it's not available in 2007, I think.

Both the Dir and FSO methods are quite straightforward.

To get more info on them I would suggest either a board or web search.

I know that if I do a search I can find some good resources, just don't have time to post a link or example code, sorry.:)
 
Upvote 0
Have spent last hour or so looking for some resources but not found anything that has solved my problem.

If anyone knows of any links it would be appreciated if you could drop them onto this thread.


Many thanks
 
Upvote 0
Are you sure you found nothing?

If I google on FileSystemObject I get over 500K hits.

And if I include VBA in the search I get over 60K hits, like this one.
 
Upvote 0
I do get a lot of hits, but nothing specifically dealing with looping through folders in a named path.....:(
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top