|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
多工作簿合并- Sub ykcbf() '//2024.6.26 多工作簿汇总
- Set fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Set sh = ThisWorkbook.Sheets("汇总表")
- sh.UsedRange.Clear
- p = ThisWorkbook.Path & ""
- For Each f In fso.GetFolder(p).Files
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- m = m + 1
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets("Sheet1")
- r = IIf(m = 1, 1, sh.Cells(Rows.Count, 2).End(3).Offset(1).Row)
- r1 = .Cells(Rows.Count, 2).End(3).Row
- .UsedRange.Offset(IIf(m = 1, 0, 2)).Copy sh.Cells(r, 1)
- End With
- wb.Close 0
- End If
- Next f
- With sh
- r = .Cells(Rows.Count, 2).End(3).Row
- .UsedRange.Offset(r).Clear
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|