|
代码如下。。。
Public col As New Collection, s As Variant
Sub test()
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Set sht = wb.Sheets(1)
s = sht.[a1].Value
p = wb.Path & "\"
Set fso = CreateObject("scripting.filesystemobject")
Set d = CreateObject("scripting.dictionary")
m = 1: n = 1
ReDim brr(1 To 10000, 1 To 100)
brr(1, 1) = "名称"
Call 子目录(fso, p)
For i = 1 To col.Count
m = m + 1
x = Len(col(i)) - Len(Replace(col(i), "\", ""))
ss = Split(col(i), "\")(x - 1)
brr(1, m) = ss
With Workbooks.Open(col(i), 0).Sheets(1)
arr = .[a1].CurrentRegion
.Parent.Close 0
End With
For j = 1 To UBound(arr)
sss = arr(j, 1)
If Not d.exists(sss) Then n = n + 1: d(sss) = n
nn = d(sss)
brr(nn, 1) = sss
brr(nn, m) = brr(nn, m) + arr(j, 2)
Next
Next
sht.[l3].Resize(n, m) = brr
Beep
Set col = New Collection
Set d = Nothing
Application.ScreenUpdating = True
End Sub
Sub 子目录(fso, p)
For Each file In fso.getfolder(p).Files
If InStr(file, s) And Left(file.Name, 2) <> "~$" Then col.Add file.Path
Next
For Each folder In fso.getfolder(p).subfolders
子目录 fso, folder
Next
End Sub
|
|