Here's one way. Change strDir to suit. Adds a new sheet to the
ActiveWorkbook and lists the files in the first Column.
Sub ListFiles()
Dim intI As Integer
Dim rngList As Range
Dim strFile As String
Dim strDir As String
Dim wShtList As Worksheet
strDir = "C:\Backup"
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = strDir
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
Set wShtList = ActiveWorkbook.Sheets.Add
wShtList.Name = "File Listing"
Set rngList = wShtList.Cells(1, 1)
For intI = 1 To .FoundFiles.Count
rngList.Value = GetFileName(.FoundFiles(intI))
Set rngList = rngList(2, 1)
Next intI
End If
End With
Application.ScreenUpdating = True
End Sub
Function GetFileName(strPath As String)
'' Used to retrieve the filename from a full path.
Dim intLoc As Integer
Dim strTemp As String
Dim strSep As String
strSep = Application.PathSeparator
strTemp = strPath
intLoc = 1
While InStr(intLoc, strTemp, strSep) > 0
intLoc = InStr(intLoc, strTemp, strSep) + 1
Wend
GetFileName = Right(strTemp, Len(strTemp) - intLoc + 1)
End Function
Tested using Excel 97SR2 on Windows 98SE,
HTH
Paul