|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
具体你要看一下FSO,里面有一遍就是介绍遍历文件夹的。具体地址有点忘了。
- '内容参考至EXCELHOME
- Public fso As Object
- Public ff 'FILE FOLDER
- Public f 'FILE
- Public fsd 'FILE SUBFOLDER
- Public wb As Workbook, sht As Worksheet
- Public n As Long, arrOut
- Sub FSO_20150923()
- ReDim arrOut(0 To 1000, 0 To 11) 'Need Consider if >65536
- arrOut(0, 0) = "工作表": arrOut(0, 1) = "序号": arrOut(0, 2) = "目录"
- arrOut(0, 3) = "圆片名称": arrOut(0, 4) = "卡号": arrOut(0, 5) = "总片数":
- arrOut(0, 6) = "余片": arrOut(0, 7) = "可出库料": arrOut(0, 8) = "未测片"
- arrOut(0, 9) = "批次良率": arrOut(0, 10) = "来料日期": arrOut(0, 11) = "测试日期"
- Sheets("统计表").UsedRange.ClearContents
- GetFolder (ThisWorkbook.Path)
- Sheets("统计表").[A1].Resize(UBound(arrOut) + 1, UBound(arrOut, 2) + 1) = arrOut
- End Sub
- Sub GetFolder(ByVal pth)
- Dim arr
- Set fso = CreateObject("scripting.filesystemobject")
- Set ff = fso.GetFolder(pth)
- For Each f In ff.Files
- If InStr(Split(f.Name, ".")(UBound(Split(f.Name, "."))), "xl") > 0 Then
- If Not f.Name = ThisWorkbook.Name Then
- Set wb = Workbooks.Open(f)
- For Each sht In wb.Sheets
- arr = sht.UsedRange
- ReadinOut (arr)
- Next sht
- wb.Close False
- End If
- End If
- Next f
- For Each fsd In ff.subfolders
- GetFolder (fsd)
- Next fsd
- End Sub
- Sub ReadinOut(arr)
- Dim i As Long, j As Long
- For i = 2 To UBound(arr)
- If n = 65536 Then Stop
- n = n + 1
- arrOut(n, 0) = f.Name & "/" & sht.Name
- For j = 1 To UBound(arr, 2)
- arrOut(n, j) = arr(i, j)
- Next j
- Next i
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|