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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

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,118,788
Messages
5,574,291
Members
412,584
Latest member
Leow
Top