|
改一下,连标题行一起提取。- Sub ykcbf() '//2024.8.14
- Set fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("Sheet1")
- p = ThisWorkbook.Path & ""
- ReDim brr(1 To 1000, 1 To 200)
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- n = n + 1
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 2)
- wb.Close False
- End With
- If n = 1 Then
- m = m + 1
- For i = 1 To UBound(arr)
- brr(m, i) = arr(i, 1)
- Next
- End If
- m = m + 1
- For i = 1 To UBound(arr)
- brr(m, i) = arr(i, 2)
- Next
- End If
- End If
- Next f
- With sh
- .UsedRange.ClearContents
- .[a1].Resize(m, r) = brr
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|