|
多工作簿多工作表合并- Sub ykcbf() '//2024.7.11
- Dim wb, ws
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set ws = ThisWorkbook
- p = ThisWorkbook.Path & ""
- On Error Resume Next
- For Each sht In ws.Sheets
- If InStr(sht.Name, "操作") = 0 Then
- sht.Delete
- End If
- Next
- For Each f In fso.GetFolder(p).Files
- If InStr(f, ws.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- d(sht.Name) = ""
- Next
- wb.Close 0
- End If
- Next f
- For Each k In d.keys
- m = 0
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In fso.GetFolder(p).Files
- If InStr(f, ws.Name) = 0 Then
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- If InStr(sht.Name, k) Then
- m = m + 1
- With sht
- .UsedRange.EntireRow.Hidden = False '//取消隐藏行
- .AutoFilterMode = False '//取消筛选状态
- If m = 1 Then
- Set sht1 = ws.Sheets.Add(After:=ws.Sheets(ws.Sheets.Count))
- sht1.Name = .Name
- .Cells.Copy sht1.[a1]
- Else
- r1 = ws.Sheets(sht.Name).Cells(Rows.Count, 1).End(3).Row
- .UsedRange.Offset(1).Copy ws.Sheets(sht.Name).Cells(r1 + 1, 1)
- End If
- End With
- End If
- Next
- wb.Close 0
- End If
- Next f
- Next
- ws.Sheets("操作表").Activate
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
|