快速实现多表合并
2018-11-06 本文已影响2人
杂草青
复制代码→点击工作表名称→右键→查看代码→ctrl+v→按F5→弹出“要合并的文件”对话框→选中要合并的工作表→打开→3秒后选中的工作表合并在同一个工作簿中
快速实现多表合并附:复制代码
Sub 合并工作薄()
Dim FilesToOpen
Dim x As Integer
On Error GoTo ErrHandler
Application.ScreenUpdating = False
FilesToOpen = Application.GetOpenFilename _
(FileFilter:="MicroSoft Excel文件(*.xlsx), *.xls", _
MultiSelect:=True, Title:="要合并的文件")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "没有选中文件"
GoTo ExitHandler
End If
x = 1
While x <= UBound(FilesToOpen)
Workbooks.Open Filename:=FilesToOpen(x)
Sheets().Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
MsgBoxErr.Description
Resume ExitHandler
End Sub