|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
返回本文件所在文件夹中的所有xls文件(不含自己),包含子文件夹,请参考:- 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
复制代码 |
|