1
我有一個VBA
代碼,它列出了特定文件夾中的所有文件,但它與「對象不支持此操作」錯誤失敗。任何幫助表示讚賞。謝謝!Excel VBA說對象不支持此操作?
Sub ListAllFiles()
Dim fs As FileSearch, ws As Worksheet, i As Long
Set fs = Application.FileSearch
With fs
.SearchSubFolders = True
.FileType = msoFileTypeAllFiles
.LookIn = "C:Files"
If .Execute > 0 Then
Set ws = Worksheets.Add
For i = 1 To .FoundFiles.Count
ws.Cells(i, 1) = .FoundFiles(i)
Next
Else
MsgBox "No files found"
End If
End With
End Sub
在這行參考? –
從Excel 2007開始,文件搜索不起作用。您需要使用Dir()或其他方法:https://answers.microsoft.com/zh-CN/office/forum/office_2010-customize/applicationfilesearch-not- working/771afb4f-d948-4a37-ac8f-4366336a41fc?auth = 1 –
謝謝,Scott! – John