hi,
Iam trying to find all files in my desktop but trhe code stopped in application.filesearch stating object doesnot support this action. why
Iam trying to find all files in my desktop but trhe code stopped in application.filesearch stating object doesnot support this action. why
Code:
Sub ListAllFiles()
Dim ws As Worksheet, i As Long
With Application.FileSearch
.NewSearch
.SearchSubFolders = False ' set to true if you want sub-folders included
.FileType = msoFileTypeAllFiles 'can modify to just Excel files eg with msoFileTypeExcelWorkbooks
.LookIn = "C:\" 'modify this to where you want to serach
If .Execute > 0 Then
Set ws = Worksheets.Add
For i = 1 To .FoundFiles.Count
ws.Cells(i, 1) = Mid$(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1)
Next
Else
MsgBox "No files found"
End If
End With
End Sub
Last edited by a moderator: