|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
kjq1833 发表于 2014-1-21 22:04
请问,把文件夹下(包含子文件夹)所以文件名提取到指定列(放在同一个子表中),如何实现呢?
请参考:- Sub Macro1()
- Dim Fso As Object, Folder As Object
- Dim arrf$(), mf&
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(ThisWorkbook.Path)
- Call GetFiles(Folder, arrf, mf)
- [a:a].ClearContents
- [a1].Resize(mf) = WorksheetFunction.Transpose(arrf)
- End Sub
- Sub GetFiles(ByVal Folder As Object, ByRef arrf$(), ByRef mf&)
- Dim SubFolder As Object
- Dim File As Object
- For Each File In Folder.Files
- If File.Name Like "*.xls" Then
- If File.Name <> ThisWorkbook.Name Then
- mf = mf + 1
- ReDim Preserve arrf(1 To mf)
- arrf(mf) = File
- End If
- End If
- Next
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, arrf, mf)
- Next
- End Sub
复制代码 |
|