|
参与一下。。。
- Sub ykcbf() '//2024.8.28 多表合并
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("Sheet1")
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In fso.GetFolder(p).Files
- If LCase(f.Name) Like "*.xls*" Then
- If InStr(f, "~$") = 0 Then
- If InStr(f, ws.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(3, "XFD").End(1).Column
- arr = .[a1].Resize(r, c)
- End With
- wb.Close 0
- For i = 3 To UBound(arr)
- If arr(i, 1) <> Empty Then
- m = m + 1
- brr(m, 1) = fn
- For j = 1 To UBound(arr, 2)
- brr(m, j + 1) = arr(i, j)
- Next
- End If
- Next
- End If
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(2).ClearContents
- .[a3].Resize(m, c) = brr
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|