Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have some code that will list all the files in a particular folder. Is
there a way to do the same with just the names of folders in a directory? Sub ListDir() Dim i As Long LocDir = InputBox("Copy & paste the directory you need to have listed.") With Application.FileSearch .NewSearch .LookIn = LocDir .SearchSubFolders = False .MatchTextExactly = False .FileType = msoFileTypeAllFiles If .Execute(msoSortByFileName) 0 Then MsgBox "There were " & .FoundFiles.Count & " file(s) found." For i = 1 To .FoundFiles.Count Cells(i, 2).Value = .FoundFiles(i) Next i Else MsgBox "There were no files found." End If End With Columns("B:B").Select Selection.Replace What:=LocDir, Replacement:="" _ , LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False Selection.Replace What:="\", Replacement:="" _ , LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False Range("A1").Select End Sub |