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
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

bill_reinwald

New Member
Joined
Sep 19, 2005
Messages
22
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
 

Watch MrExcel Video

Forum statistics

Threads
1,112,884
Messages
5,543,023
Members
410,583
Latest member
gazz57
Top