|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
多工作簿多表按表名合并- Sub ykcbf() '//2024.8.14 多工作簿多工作表合并
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim t: t = Timer
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("scripting.dictionary")
- Set ws = ThisWorkbook
- p = ThisWorkbook.Path & ""
- bm = [{"3原因","4离网"}]
- bt = [{2,3}]
- For x = 1 To UBound(bm)
- ws.Sheets(bm(x)).UsedRange.Clear
- Next
- 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)
- m = m + 1
- For x = 1 To UBound(bm)
- If m = 1 Then
- wb.Sheets(bm(x)).UsedRange.Cells.Copy ws.Sheets(bm(x)).[a1]
- Else
- r = ws.Sheets(bm(x)).Cells(Rows.Count, 1).End(3).Row
- wb.Sheets(bm(x)).UsedRange.Offset(bt(x)).Copy ws.Sheets(bm(x)).Cells(r + 1, 1)
- End If
- Next
- wb.Close False
- End If
- End If
- Next f
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- MsgBox "拆分完毕,共用时: " & Format(Timer - t, "0.000秒"), , "提示"
- End Sub
复制代码
|
|