|
楼主 |
发表于 2016-1-14 19:24
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Dim FileList(1 To 65536, 1 To 1), filen&
Sub FolderFileList()
'--------------------------------------------------------------------------------------------
Dim myfolder, mypath
Set myfolder = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件夹:", 0)
If Not myfolder Is Nothing Then
If myfolder <> "桌面" Then mypath = myfolder.Items.Item.Path
Else
MsgBox "你没有选择文件夹!"
Exit Sub
End If
If mypath = "" Or Left(mypath, 2) = "::" Then
MsgBox "文件夹选择错误!"
Exit Sub
End If
'------------------------------------------------------------------------------------------------
Dim fso, Folder, myf
Set fso = CreateObject("scripting.filesystemobject")
Set Folder = fso.getfolder(mypath)
filen = 0
UserForm1.Show 0
For Each myf In Folder.Files
filen = filen + 1
FileList(filen, 1) = myf
UserForm1.Label1.Caption = fileedit(myf)
DoEvents
Next myf
SubFolderFileList (mypath)
UserForm1.Caption = "文件搜索完成:"
UserForm1.Label1.Caption = "文件搜索完成,共搜索到 " & filen & " 个文件!"
DoEvents
If filen > 65536 Then filen = 65536
If filen Then [a1].Resize(filen) = FileList
filen = 0
End Sub
Function SubFolderFileList(pth)
Dim fso, Folder, SubFolder, myf, fd
Set fso = CreateObject("scripting.filesystemobject")
Set Folder = fso.getfolder(pth)
Set SubFolder = Folder.subfolders
On Error Resume Next
For Each fd In SubFolder
For Each myf In fd.Files
If myf <> "" Then
filen = filen + 1
FileList(filen, 1) = myf
UserForm1.Label1.Caption = fileedit(myf)
DoEvents
End If
Next myf
SubFolderFileList (fd.Path)
Next fd
On Error GoTo 0
End Function
Function fileedit(filenam)
Dim file1, file2, filear
If filenam > 60 Then
filear = Split(filenam, "\")
file2 = filear(UBound(filear))
file1 = Replace(filenam, file2, "")
file1 = Left(file1, 30)
fileedit = file1 & "...\" & file2
Else
fileedit = filenam
End If
End Function
|
评分
-
1
查看全部评分
-
|