|
- Sub test()
- Dim r%, i%, n%
- Dim arr$(), brr(1 To 10000, 1 To 3)
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Dim fso As New Scripting.FileSystemObject
- mypath = ThisWorkbook.Path & "\新建文件夹"
- Set f = fso.GetFolder(mypath)
- Call GetFiles(f, arr, 0)
- For k = 1 To UBound(arr)
- Set wb = GetObject(arr(k))
- With wb
- With .Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- crr = .Range("a2:c" & r)
- For i = 1 To UBound(crr)
- If crr(i, 3) = "A店" Then
- n = n + 1
- brr(n, 1) = crr(i, 1)
- brr(n, 2) = crr(i, 2)
- brr(n, 3) = crr(i, 3)
- End If
- Next
- End With
- .Close False
- End With
- Next
- With Worksheets("sheet1")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
- Sub GetFiles(ByVal Folder As Object, arr$(), m&)
- Dim SubFolder As Object
- Dim File As Object
- For Each File In Folder.Files
- If File.Name Like "*.xls*" Then
- m = m + 1
- ReDim Preserve arr(1 To m)
- arr(m) = File
- End If
- Next
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, arr, m)
- Next
- End Sub
复制代码 |
|