|
汇总所有表
- Sub ykcbf2() '//2024.9.29 汇总表自动生成
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("汇总")
- sh.Cells.Clear
- ReDim brr(1 To 100000, 1 To 100)
- m = 1: n = 0
- For Each f In fso.GetFolder(p).Files
- If LCase(f.Name) Like "*.xls*" Then
- If InStr(f, "~$") = 0 Then
- If InStr(f, ThisWorkbook.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- fn = fso.GetBaseName(f)
- For Each sht In wb.Sheets
- n = n + 1
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(1, "XFD").End(1).Column
- arr = .[a1].Resize(r, c)
- Max = IIf(Max < c, c, Max)
- If n = 1 Then
- brr(1, 1) = "工作簿名"
- brr(1, 2) = "工作表名"
- For j = 1 To UBound(arr, 2)
- brr(1, j + 2) = arr(1, j)
- Next
- End If
- For i = 2 To UBound(arr)
- m = m + 1
- brr(m, 1) = fn
- brr(m, 2) = .Name
- brr(m, 3) = m
- For j = 2 To UBound(arr, 2)
- brr(m, j + 2) = arr(i, j)
- Next
- Next
- End With
- Next
- wb.Close 0
- End If
- End If
- End If
- Next
- With sh
- .UsedRange.Clear
- .[a1].Resize(1, Max + 2).Interior.Color = 49407
- With .[a1].Resize(m, Max + 2)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|