Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello
I know how to use the File.Search function. What do I do if I only want the names of the folders in a particular direectory instead of the files? Thank you! W |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
find below a repost from Bob Phillips. Change the starting directory and use the macro 'Folders' Frank Dim FSO As Object Dim cnt As Long Dim level As Long Dim arFiles Sub Folders() Dim i As Long Set FSO = CreateObject("Scripting.FileSystemObject") arFiles = Array() cnt = 0 level = 1 ReDim arFiles(1, 0) arFiles(0, 0) = "C:\myTest" arFiles(1, 0) = level SelectFiles "C:\myTest" cnt = 0 For i = LBound(arFiles, 2) To UBound(arFiles, 2) ActiveSheet.Cells(i + 1, arFiles(1, i)).Value = arFiles(0, i) Next End Sub '---------------------------------------------------------------------- Sub SelectFiles(sPath) '---------------------------------------------------------------------- Dim fldr As Object Dim Folder As Object Set Folder = FSO.Getfolder(sPath) level = level + 1 For Each fldr In Folder.Subfolders cnt = cnt + 1 ReDim Preserve arFiles(1, cnt) arFiles(0, cnt) = fldr.Name arFiles(1, cnt) = level SelectFiles fldr.Path level = level - 1 Next End Sub -- Regards Frank Kabel Frankfurt, Germany cogent wrote: Hello I know how to use the File.Search function. What do I do if I only want the names of the folders in a particular direectory instead of the files? Thank you! W |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try something like the following:
Dim FSO As Object Dim Fldr As Object Const FOLDER_NAME = "C:\Temp" Set FSO = CreateObject("Scripting.FileSystemObject") For Each Fldr In FSO.getfolder(FOLDER_NAME).subfolders Debug.Print Fldr.Name Next Fldr -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "cogent" wrote in message ... Hello I know how to use the File.Search function. What do I do if I only want the names of the folders in a particular direectory instead of the files? Thank you! W |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Functions (search within search result) reply to this please | Excel Worksheet Functions | |||
search folder/directory for a phrase inside excel files | Excel Discussion (Misc queries) | |||
How do I search excel spreadsheets using multiple search criteria. | Excel Worksheet Functions | |||
Check if directory empty OR no of files in directory. | Excel Programming | |||
Directory search screen | Excel Programming |