Excel提取指定文件夹内的所有文件名

Excel提取指定文件夹内的所有文件名。

Sub 提取指定文件夹内的所有文件名() '含所有子文件夹内的文件
Dim Fso As Object, arrf$(), mf&
Set Fso = CreateObject("Scripting.FileSystemObject")
Call GetFiles(CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件夹", 0, "").Self.Path, Fso, arrf, mf)
[b1].Resize(mf) = Application.Transpose(arrf)
Set Fso = Nothing
End Sub
Private Sub GetFiles(ByVal sPath$, ByRef Fso As Object, ByRef arrf$(), ByRef mf&)
Dim Folder As Object
Dim SubFolder As Object
Dim File As Object
Set Folder = Fso.GetFolder(sPath)
For Each File In Folder.Files
mf = mf + 1
ReDim Preserve arrf(1 To mf)
arrf(mf) = File.Name
Next
For Each SubFolder In Folder.SubFolders
Call GetFiles(SubFolder.Path, Fso, arrf, mf)
Next
Set Folder = Nothing
Set File = Nothing
End Sub

 

Excel技巧

Excel去除首尾空格公式

2017-9-10 16:29:32

Excel技巧

Excel提取指定目录的文件夹名和文件名

2017-9-10 21:29:49

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索