Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 295
Default Opening subfolders in sequence

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Opening subfolders in sequence

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.

"Brettjg" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 295
Default Opening subfolders in sequence

Ok, thanks Joel, I'll do some testing on that. Brett

"Brettjg" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Opening subfolders in sequence

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
--
Regards,

OssieMac


"Brettjg" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 295
Default Opening subfolders in sequence

Hi Ossiemac, yes that works nicely. TVM, Brett (your assumption is correct)

"OssieMac" wrote:

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
--
Regards,

OssieMac


"Brettjg" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add subfolders and name - Possible? Trish Smith Excel Programming 2 August 17th 08 02:29 AM
opening workbooks in subfolders Sian Excel Programming 4 February 13th 08 05:10 PM
Opening files in folders and subfolders bestie22 Excel Discussion (Misc queries) 1 September 19th 06 05:23 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM
Opening workbooks in sequence Matt Excel Programming 3 April 20th 04 06:57 PM


All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"