|
如何改为工作簿所有工作表。
- Sub 数组法合并() '//2023.3.6
- Dim p$, s%, x%, ff$, f$, arr(1 To 100), wb As Workbook
- Dim r%, m%, brr, crr
- Set zwb = ThisWorkbook
- Set sh = zwb.Sheets(1)
- sh.UsedRange.Offset(1, 0).ClearContents
- p = ThisWorkbook.Path & ""
- ff = Dir(p & "*", 16) '//子文件夹
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- Dim tm: tm = Timer
- For Each wb In Workbooks
- If wb.Name <> ThisWorkbook.Name Then wb.Close
- Next
- Do While ff <> ""
- If Not ff Like ".*" Then
- If GetAttr(p & ff) = 16 Then
- s = s + 1
- arr(s) = ff
- End If
- End If
- ff = Dir
- Loop
- On Error Resume Next
- For i = 1 To s '//子目录循环
- f = Dir(p & arr(i) & "\*汇总信息*.xls*")
- Do While f <> "" And InStr(f, ThisWorkbook.Name) = 0
- With GetObject(p & arr(i) & "" & f)
- 'With .Sheets(2)'只是工作表2,如何改为工作簿的所有工作表
-
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- brr = .Range("a2:e" & r)
- r2 = sh.Cells(sh.Rows.Count, "a").End(xlUp).Row + 1
- sh.Cells(r2, 1).Resize(r - 1, 5).Value = brr
- End With
- .Close False
- End With
- f = Dir
- Loop
- Next
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- MsgBox "运行完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码 |
|