批处理 多个excel合并成一个excel(不是首尾相接copy *.csv des.csv)

2025-02-02 13:59:20
推荐回答(1个)
回答1:

将这些文件copy到一个文件夹,建一新Excel,也存到该文件夹。仅打开该新Excel,按Alt+F11,点菜单的插入,模块,粘贴如下代码:
Sub Find()
Application.ScreenUpdating = False
Dim MyDir As String
MyDir = ThisWorkbook.Path & "\"
ChDrive Left(MyDir, 1) 'find all the excel files
ChDir MyDir
Match = Dir$("")
Do
If Not LCase(Match) = LCase(ThisWorkbook.Name) Then
Workbooks.Open Match, 0 'open
ActiveSheet.Copy Before:=ThisWorkbook.Sheets(1) 'copy sheet
Windows(Match).Activate
ActiveWindow.Close
End If
Match = Dir$
Loop Until Len(Match) = 0
Application.ScreenUpdating = True
End Sub
在此界面之间按F5运行此宏,所有表格复制到一个Excel里了。