|
本帖最后由 7837323 于 2023-6-30 16:34 编辑
Sub 合并当前目录下所有工作簿()
Dim wb, ws, title_row, end_row, copy_title, file_path, file_name, save_file, fso As Object
'--------------------参数填写:title_row,数字,第1行为1向下递增;end_row,数字;file_path,合并文件夹
title_row = 1 '表头行数,仅复制1次;如果为0,则表示没有表头或表头每次都复制
end_row = 0 '表尾行数,不参与合并
Application.ScreenUpdating = False
MyPath = ActiveWorkbook.Path
MyName = Dir(MyPath & "\" & "*.xlsx")
AWbName = ActiveWorkbook.Name
Do While MyName <> ""
If MyName <> AWbName Then
Set wb = Workbooks.Open(MyPath & "\" & MyName)
c = ThisWorkbook.Sheets("sheet1").UsedRange.SpecialCells(xlCellTypeLastCell).Row
If c = 1 Then '防止合并的工作簿第一行空着
c = 0
End If
ActiveSheet.UsedRange.Copy ThisWorkbook.Sheets("sheet1").Cells(c + 1, 1) '合并工作簿的第一个sheet名字为:sheet1
wb.Close False
End If
MyName = Dir
Loop
Application.ScreenUpdating = True
MsgBox "已完成"
End Sub
|
|