Opening subfolders in sequence

B

Brettjg

Let's say I have a main folder with a path of
C:\2. SETTLED CLIENTS\

I want to loop through all the sub folders within it to extract information
from one file within each folder. I know the code for extracting the info and
opening the file.

Each subfolder is of the name "Surname, initial"

What I don't know is the code to open each subfolder in sequence, without
using a list of names.
Regards, Brett
 
J

Joel

Once you got yher foler then this

for each fld in folders
for each fname in fld.files

next fname

next fld


If you add a watch into your VBA window for fld you can see the properties
like files.

Add the watch by highlighting any variable in your code and then right click
and select Watch. Put a break point in your code by click on a line of VBA
code and presssing F9. Step through the code by pressing F8.
 
O

OssieMac

Not sure how much you are looking for here Brett. I am assuming that all of
these directors are simply attached to one directory and not sub directory of
subdirectory.

The following is extracted and modified a bit from Help in xl2002 just to
identify one level of sub directories from a given directory.

Sub test()
Dim MyPath As String
Dim MyName As String

MyPath = "C:\2. SETTLED CLIENTS\"

MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.

Do While MyName <> "" ' Start the loop.
'Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
MsgBox MyName ' Display entry only if it is a directory
End If

End If

MyName = Dir ' Get next entry.

Loop

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top