|
请参考,老师们到代码!
http://club.excelhome.net/thread-1082009-1-1.html
Dim Folder As Object
Dim SubFolder As Object
Dim File As Object
Set Folder = Fso.GetFolder(sPath)
For Each File In Folder.Files
If File.Name Like sFileType Then
If File.Name <> ThisWorkbook.Name Then
m = m + 1
ReDim Preserve arr(1 To 2, 1 To m)
arr(1, m) = sPath & "\"
arr(2, m) = File.Name
End If
End If
Next
If Folder.SubFolders.Count > 0 Then
For Each SubFolder In Folder.SubFolders
Call GetFiles(SubFolder.Path, sFileType, Fso, arr, m)
Next
End If
Set Folder = Nothing
Set File = Nothing
Set SubFolder = Nothing
End Sub
Sub 文件列表()
Dim f$, Fso As Object, sFileType$, i&, arr$(), brr$(), m&
sFileType = "*.*"
Set Fso = CreateObject("Scripting.FileSystemObject")
Call GetFiles(ThisWorkbook.Path, sFileType, Fso, arr, m)
If m = 0 Then
MsgBox "没有发现文件!", vbInformation
Exit Sub
End If
For i = 1 To m
Cells(i + 1, 1) = arr(1, i) & arr(2, i)
Next
MsgBox "处理完毕", vbInformation
Set Fso = Nothing
End Sub |
|