【FileSystemObject】
excel2007吧
全部回复
仅看楼主
level 5
siaojuen 楼主
FileSystemObject 可用来处理指定文件夹及其下多层子孙文件夹。
以下两个程序,使用时只执行第一个:sub xxx(),然后由第一个自动执行第二个。
第二个程序是递回程序,它搜过文件夹后就带著子文件夹呼叫自己,这就可达到搜索多层子文件夹的目的。
适用於 excel 2003 及 2007 。
Private Sub xxx()
getfiles ThisWorkbook.path
End Sub
Private Sub getfiles(path)
Dim fso, ff, f, nrow
Set fso = CreateObject("Scripting.FileSystemObject")
Set ff = fso.getfolder(path)
For Each f In ff.Files
If f.Name Like "*.xls" Or f.Name Like "*.xlsx" Then
nrow = [a60000].End(xlUp).Row
Cells(nrow + 1, 1) = path & "\" & f.Name
End If
Next
For Each f In ff.subfolders
getfiles f
Next
End Sub

2012年04月11日 12点04分 1
1