1. 将需要合并的Excel放入1个文件夹内
2. 在新建的文件夹内,新建1个Excel——>右击Sheet1——>点击“查看代码”
3. 贴入代码
Sub 合并Excel()
Dim FileOpen
Dim X As Integer
Application.ScreenUpdating = False
FileOpen = Application.GetOpenFilename(FileFilter:="Microsoft Excel文件(.xlsx),.xlsx", MultiSelect:=True, Title:="合并Excel")
X = 1
While X <= UBound(FileOpen)
Workbooks.Open Filename:=FileOpen(X)
Sheets().Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
X = X + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Exit Sub
errhadler:
MsgBox Err.Description
End Sub
4. 运行代码
5. 弹出框—>全选—>需要合并的Excel
最后删除Sheet1 ,保存文件。