新建一个工作表,命名后保存到和与合并的N个文件同一个文件文件夹,按 alt + f11,双击工程资源管理器里面的sheet1(sheet1),在右侧的代码区粘贴如下代码。运行。等候一会就OK了。
宏:多个文件表合到一个文件表的多个SHEET中
Sub CombineWorkbooks() Dim FilesToOpen, ft Dim x As Integer Application.ScreenUpdating = False On Error GoTo errhandler FilesToOpen = Application.GetOpenFilename _ (FileFilter:="Micrsofe Excel文件(*.xls), *.xls", _ MultiSelect:=True, Title:="要合并的文件") If TypeName(FilesToOpen) = "boolean" Then MsgBox "没有选定文件" 'GoTo errhandler End If x = 1 While x <= UBound(FilesToOpen) Set wk = Workbooks.Open(Filename:=FilesToOpen(x)) wk.Sheets().Move after:=ThisWorkbook.Sheets _ (ThisWorkbook.Sheets.Count) x = x + 1 Wend MsgBox "合并成功完成!" errhandler: 'MsgBox Err.Description 'Resume errhandler End Sub