Sub
test()
With
Application.FileSearch
'寻找的目录是当前工作薄拆让悉所在的目录
.LookIn
=
ThisWorkbook.Path
'只寻找文件,不寻找下级目录
.SearchSubFolders
=
False
'要找的文件是XLS文件
.FileType
=
msoFileTypeExcelWorkbooks
'寻找
.NewSearch
'如果找到文件,.execute()将大于0
'找到的文件总数是.foundFilescount
'以下是把找到的文件名称全部显示在表滑洞格中
If
.Execute()
>
0
Then
For
i
=
1
To
.FoundFiles.Count
Cells(i,
1)
=
.FoundFiles(i)
Next
End
If
End
With
End
Sub
【引用位置】 https://blog.csdn.net/pashine/article/details/42100237
'-------------------------------------------
'获取某文件夹下的所有Excel文件
'-------------------------------------------
Sub getExcelFile(sFolderPath As String)
On Error Resume Next
Dim f As String
Dim file() As String
Dim x
k = 1
ReDim file(1)
file(1) = sFolderPath &""
End Sub
'-------------------------------------------
'获取某文件夹下的所有文件和子扰者好目录下的文件
'-------------------------------------------
Sub getAllFile(sFolderPath As String)
'Columns(1).Delete
On Error Resume Next
Dim f As String
Dim file() As String
Dim i, k, x
x = 1
i = 1
k = 1
ReDim file(1 To i)
file(1) = sFolderPath &""
'-- 获得所有子目录
Do Until i >k
f = Dir(file(i), vbDirectory)
Do Until f = ""
If InStr(f, ".") = 0 Then
k = k + 1
ReDim Preserve file(1 To k)
file(k) = file(i) &f &""
End If
f = Dir
Loop
i = i + 1
Loop
'-- 获得所有子目录下的所有文件
For i = 1 To k
f = Dir(file(i) &" . ")'通嫌塌配符 . 表示所有文件,*.xlsx Excel文件
Do Until f = ""
'Range("a" &x) = f
Range("a" &x).Hyperlinks.Add Anchor:=Range("缓铅a" &x), Address:=file(i) &f, TextToDisplay:=f
x = x + 1
f = Dir
Loop
Next
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)