VBA and Subfolder Drill downs

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
Hey everyone! I asked a similar question on another thread, and didn't get any responses. Then I realized how broad a question I was asking. I am going to get more specific about where I am confused. Also, I am getting pretty comfortable with the code, but struggle with the logic/syntax of loops. Anyone wanting to explain how they do it would be greatly appreciated.
Ok, I would like to create a loop which does the following:

Dim File_Path As String

File_Path = "Desktop/Sandbox"

'Here is my question -->' If an excel filename in File_Path (including subfolders) contains text "Example" Then

'Do things'

Else
End If
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
It is still not terribly clear.
Do you want to onow how to loop through the files?
There are at least two ways t do this in principle:
1. Use File system object to loop through all folders and get all file names. The procedure requires recursion ( it calls itself again to go to the next level subfoler.
2. Better IMO (and for sure times faster) is to use the result of DIR path/*.* /s /b comman recorded in a file or copied in the clipboard. Then you just have to check each line for Example.

There are examples for each online. Later I can also post something if you cannot find.
 
Upvote 0
Holy smokes.... Thank you for your reply. In researching the DIR function I just found a really powerful tool Microsoft has created for users in Excel. I had never heard of a "Power Query" before, but it can do 95% what I was going to write this macro to do.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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