|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我自己也编了一个,方法不一样的,大家参考,用递归
Sub Macro1()
'
Dim fs, f, f1, s, sf1, j%
j = 1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("F:\book\hf")
Set sf = f.SubFolders
Call Macro2(j, f)
End Sub
Sub Macro2(j, sf1)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(sf1)
Set sf = f.SubFolders
If sf.Count <> 0 Then
For Each f1 In sf
's = s & f1.Name
's = s & vbCrLf
Call Macro2(j, f1)
Call c(f1, j)
Next
End If
'MsgBox s
End Sub
Sub c(aa, j)
Dim fs, f1, i%
i = j
'Cells(i, 2) = aa.Name
'i = i + 1
Set fs = CreateObject("Scripting.FileSystemObject")
For Each f1 In fs.GetFolder(aa).Files
Cells(i, 1) = f1.Name
'Cells(i, 2) = aa.Name
Cells(i, 2) = aa.Path
i = i + 1
Next f1
j = i
End Sub |
|