Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Finding Folders

Hi,

Excel 97

Using the Dir function I have few problems with finding/listing files in
Drives/Folders/Subfolders etc. providing that I know the path.

How would I go about finding Folders in a Drive, Subfolders in a Folder
etc.?

Any help will be gratefully received.

Regards,
Don.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Finding Folders

Don,

Google "File System Object" or "FSO". This ActiveX object will do exactly
what you need. For example, this Excel code lists all of the folders
immediately under the C:\ drive:

Sub runFolderList()
On Error Resume Next
Dim rootFolder
Dim subFolders
Set fso = CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder("C:\")
Set subFolders = rootFolder.subFolders

For Each folder In subFolders
Debug.Print "Folder: " & folder.Name
Next

Set subFolders = Nothing
Set rootFolder = Nothing
Set fso = Nothing
End Sub

Hope this helps,

Stan Scott
New York City
"Don Lloyd" wrote in message
...
Hi,

Excel 97

Using the Dir function I have few problems with finding/listing files in
Drives/Folders/Subfolders etc. providing that I know the path.

How would I go about finding Folders in a Drive, Subfolders in a Folder
etc.?

Any help will be gratefully received.

Regards,
Don.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Finding Folders

Thank you Stan,

It worked a treat.

Don

"Stan Scott" wrote in message
...
Don,

Google "File System Object" or "FSO". This ActiveX object will do exactly
what you need. For example, this Excel code lists all of the folders
immediately under the C:\ drive:

Sub runFolderList()
On Error Resume Next
Dim rootFolder
Dim subFolders
Set fso = CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder("C:\")
Set subFolders = rootFolder.subFolders

For Each folder In subFolders
Debug.Print "Folder: " & folder.Name
Next

Set subFolders = Nothing
Set rootFolder = Nothing
Set fso = Nothing
End Sub

Hope this helps,

Stan Scott
New York City
"Don Lloyd" wrote in message
...
Hi,

Excel 97

Using the Dir function I have few problems with finding/listing files in
Drives/Folders/Subfolders etc. providing that I know the path.

How would I go about finding Folders in a Drive, Subfolders in a Folder
etc.?

Any help will be gratefully received.

Regards,
Don.






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
Must have feature - Tab Folders headly Excel Discussion (Misc queries) 4 December 22nd 09 09:24 PM
linking folders Trisha Excel Discussion (Misc queries) 0 August 25th 09 08:56 PM
Changing Folders! Philip J Smith Excel Worksheet Functions 0 December 7th 07 03:38 PM
To create folders using VBA Sri Excel Discussion (Misc queries) 1 February 4th 05 01:13 PM
Creating folders with VB Foss Excel Programming 2 February 24th 04 10:08 AM


All times are GMT +1. The time now is 03:50 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"