|
你的整合进来了。
你直接调用 call listdirs 你的数据路径- Sub ListDirs(ByVal Path As String)
- '文件名
- Dim filename$
- '文件夹数组
- Dim arrPath()
- '当前搜索的文件夹
- Dim sPath$
- '计数变量
- Dim i&, j&
- i = 1: j = 1
- ReDim arrPath(1 To 1)
- arrPath(i) = Path & Application.PathSeparator
- 'On Error Resume Next
- sPath = arrPath(j)
- 'Debug.Print sPath
- Do While Len(sPath)
- '搜索文件和文件夹(无属性设置的)
- filename = Dir(sPath & "*.*", vbDirectory + vbNormal)
- Do While Len(filename)
- '跳过. 和 .. 文件夹
- If Not (filename = "." Or filename = "..") Then
- '判断是否为文件夹
- If (GetAttr(sPath & "" & filename) And vbDirectory) = 16 Then
- '避免读取错误
- If Err.Number <> 0 Then Err.Clear: GoTo End1If
- i = i + 1
- '把搜索到的子文件夹放入数组中
- ReDim Preserve arrPath(1 To i)
- arrPath(i) = sPath & filename & Application.PathSeparator
- Else
- '在在此处加入针对文件处理的代码
- '
- '
- '
- If filename <> ThisWorkbook.Name And upper(filename) Like "*.XLS" Then
- Set AK = Workbooks.Open(sPath & filename) '打开符合要求的文件
- For i = 6 To 65536 Step 1
- If AK.Sheets(1).Cells(i, 1).Value <> "" Then
- Else
- Exit For
- End If
- Next
- aRow = i - 1
- tRow = ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Row + 1
- If tRow < 5 Then tRow = 5
- arr = AK.Sheets(1).Range("a6:q" & aRow)
- ThisWorkbook.Sheets(1).Range("A" & tRow).Resize(UBound(arr), UBound(arr, 2)) = arr
- ThisWorkbook.Sheets(1).Range("R" & tRow).Resize(UBound(arr), 1) = AK.Sheets(1).Range("c2")
- Workbooks(filename).Close False '关闭源工作簿,并不作修改
- End If
- End If
- End1If:
- filename = Dir
- Loop
- j = j + 1
- If j > i Then Exit Do
- sPath = arrPath(j)
- Loop
- End Sub
复制代码 |
|