时间:2016-10-10 10:14:00
Private Sub 遍历_Click()
Application.ScreenUpdating = False
Dim fso, folder, fds, fd, folder1, folder2, fs, f
Dim dirpath, atdirname, atfilename As String, arr
Dim putrows As Integer
dirpath = ThisWorkbook.Path
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.GetFolder(dirpath) '获得文件夹
Set fds = folder1.SubFolders '子文件夹集合
putrows = 5
For Each fd In fds '遍历子文件夹
'Debug.Print fd.Name
If fd.Name = "目录" Then
atdirname = fd.Name
Set folder2 = fd '获得文件夹2
Set fs = folder2.Files '文件集合
For Each f In fs '遍历文件
If f.Type = "Microsoft Excel 97-2003 工作表" Or f.Type = "Microsoft Excel 工作表" Then
'是表格文件
'Debug.Print f.Name
'执行其他操作.....
End If
Next
'Debug.Print
'putrows = putrows + 1
End If
Next
End Sub