Display a list of Excel files at a specific location

bruty

Active Member
Joined
Jul 25, 2007
Messages
448
Is there any way in Excel to create a list of all Excel files in a given network address?

ie If cell A1 has the network address 'C:\File List\' I am looking for some code or some other way to list in the cells underneath all the Excel files in that directory.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

wob

Board Regular
Joined
May 21, 2002
Messages
105
This should do what you want.
B3 should have the path. C3 should have .xls
Creates a textfile on your C: drive



Dim SearchPath As String
Dim SearchSuffix As String

SearchPath = Range("B3").Value
SearchSuffix = Range("c3").Value

Set fs = Application.FileSearch
With fs
.LookIn = SearchPath
.SearchSubFolders = True
.FileName = SearchSuffix

If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."

Open "h:\excellist.txt" For Output As #1
For i = 1 To .FoundFiles.Count
Print #1, .FoundFiles(i)
Next i
Close #1
MsgBox "c:\excellist.txt updated"

Else
MsgBox "There were no files found."
End If
End With
'
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,130,186
Messages
5,640,688
Members
417,161
Latest member
Devon150

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top