|
多簿合并- Sub ykcbf() '//2024.7.26
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("Sheet1")
- sh.UsedRange.Clear
- bt = 4: m = 0
- For Each f In fso.GetFolder(p).Files
- If LCase(f.Name) Like "*.xls*" Then
- If InStr(f, "~$") = 0 Then
- If InStr(f, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- m = m + 1
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r1 = .Cells(Rows.Count, 1).End(3).Row
- .Cells(bt + 1, 3).Resize(r1 - bt) = fn
- If m = 1 Then
- .Cells.Copy sh.Cells(1, 1)
- Else
- r = sh.Cells(Rows.Count, 1).End(3).Offset(1).Row
- .UsedRange.Offset(bt).Copy sh.Cells(r, 1)
- End If
- End With
- wb.Close 0
- End If
- End If
- End If
- Next
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|