ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Subdirectories (https://www.excelbanter.com/excel-programming/308523-subdirectories.html)

Skip[_4_]

Subdirectories
 
Hello all,

I've seen various Macros that will list files in a Directory. I'm looking
for a Macro that will list subdirectories in a directory. I would like the
Macro result printed to a blank sheet in a single column just containing the
sub-directory name. It only needs to go down 1 level - don't need
sub-directories in sub-directories. The plan is to use this data to populate
a listbox - unless the listbox could be populated directly.

Is this possible?

Many thanks.

Paul.



Jake Marx[_3_]

Subdirectories
 
Hi Paul,

Skip wrote:
I've seen various Macros that will list files in a Directory. I'm
looking for a Macro that will list subdirectories in a directory. I
would like the Macro result printed to a blank sheet in a single
column just containing the sub-directory name. It only needs to go
down 1 level - don't need sub-directories in sub-directories. The
plan is to use this data to populate a listbox - unless the listbox
could be populated directly.


You can use the FileSystemObject to do this pretty easily. The following
code assumes you have a ListBox on Sheet1 named "lstSubFolders":

Sub PopulateSubFolders()
Dim fso As Object
Dim fol As Object

Sheet1.lstSubFolders.Clear

Set fso = CreateObject("Scripting.FileSystemObject")
For Each fol In fso.GetFolder("C:\Program Files").SubFolders
Sheet1.lstSubFolders.AddItem fol.Name
Next fol

Set fso = Nothing
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


MD

Subdirectories
 
Refer to Steve Yandl's post on 08/25/2004 You will find some help ther

MD


"Skip" a écrit dans le message de
...
Hello all,

I've seen various Macros that will list files in a Directory. I'm looking
for a Macro that will list subdirectories in a directory. I would like the
Macro result printed to a blank sheet in a single column just containing

the
sub-directory name. It only needs to go down 1 level - don't need
sub-directories in sub-directories. The plan is to use this data to

populate
a listbox - unless the listbox could be populated directly.

Is this possible?

Many thanks.

Paul.





Tom Ogilvy

Subdirectories
 
also see the help example for the Dir command

--
Regards,
Tom Ogilvy

"Skip" wrote in message
...
Hello all,

I've seen various Macros that will list files in a Directory. I'm looking
for a Macro that will list subdirectories in a directory. I would like the
Macro result printed to a blank sheet in a single column just containing

the
sub-directory name. It only needs to go down 1 level - don't need
sub-directories in sub-directories. The plan is to use this data to

populate
a listbox - unless the listbox could be populated directly.

Is this possible?

Many thanks.

Paul.





Skip[_4_]

Subdirectories
 
Thanks all - advice much appreciated

"Tom Ogilvy" wrote in message
...
also see the help example for the Dir command

--
Regards,
Tom Ogilvy

"Skip" wrote in message
...
Hello all,

I've seen various Macros that will list files in a Directory. I'm

looking
for a Macro that will list subdirectories in a directory. I would like

the
Macro result printed to a blank sheet in a single column just containing

the
sub-directory name. It only needs to go down 1 level - don't need
sub-directories in sub-directories. The plan is to use this data to

populate
a listbox - unless the listbox could be populated directly.

Is this possible?

Many thanks.

Paul.








All times are GMT +1. The time now is 12:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com