Opening files in a sub-folder

bill_reinwald

New Member
Joined
Sep 19, 2005
Messages
22
I have a folder with various sub-folders in it, and I want to open up certain files within these sub-folders. I thought it would be easy enough to just add "\*" to the folder path, but VBA doesn't seem to like/understand this. Here's a snippet of code:

---------------
strPath = "\\CAISO-data\CAISO-Act4\LoadedFiles\" & "ISO " & pyear & dmonth & "\*"
strFile = Dir(strPath & "*.txt")

Do While strFile <> ""
.
.
.
------------------

But, it can't find any files using this and gives a bad name error when trying to assign to strFile. I know this code (without the last "\*") works fine as I use it all the time, shouldn't a sub-folder(s) be an easy addition?

thanks,

bill
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Anyone?

I just have a folder like C:\Main

In it are 2+ subfolders, lets say Sub1 and Sub2.

In those subs are a bunch of text files.

I want to open each text file one at a time, can't I just plug a "*" onto the path to check each subdirectory? It seems like it should be very easy, but the only thing I can find when doing searches is code that is like 40 lines long, which seems a bit overkill. VBA obviously understands what the * is for filenames, why not folders?

thanks in advance,

bill
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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