|
本帖最后由 hasyh2008 于 2022-5-17 13:14 编辑
Sub 复制()
Dim MyName As String
Dim Arr(), Brr
Dim K%
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Set Wb1 = ThisWorkbook
MyName = Dir(ThisWorkbook.Path & "\", vbDirectory)
K = 1
Do While MyName <> ""
If InStr(MyName, ".xlsx") > 0 Then
ReDim Preserve Arr(1 To K)
Arr(K) = ThisWorkbook.Path & "\" & MyName
K = K + 1
End If
MyName = Dir
Loop
Application.ScreenUpdating = False
Set Wb1 = ThisWorkbook
Wb1.Sheets(1).Range("A2:F10000") = ""
For K = 1 To UBound(Arr)
R1 = Wb1.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Set Wb2 = GetObject(Arr(K))
R2 = Wb2.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Brr = Wb2.Sheets(1).Range("A2:E" & R2)
Wb1.Sheets(1).Cells(R1 + 1, 2).Resize(UBound(Brr), 5) = Brr
Wb1.Sheets(1).Cells(R1 + 1, 1).Resize(UBound(Brr), 1) = Wb2.Name
ActiveSheet.Cells.Replace what:=".xlsx", Replacement:="", lookat:=xlPart, MatchCase:=True
Next K
Wb2.Close False
Set Wb1 = Nothing
Set Wb2 = Nothing
Application.ScreenUpdating = True
End Sub |
|