如何将100个excel文件合并成1个excel100个工作表,每个工作表名字对应原excel文件

来源:百度文库 编辑:神马文学网 时间:2024/03/29 17:59:36
将多个Excel文件合并为一个Excel文件步骤:宏--创建--输入下面内容:Sub CombineWorkbooks()Dim FilesToOpenDim x As IntegerOn Error GoTo ErrHandlerApplication.ScreenUpdating = FalseFilesToOpen = Application.GetOpenFilename _(FileFilter:="MicroSoft Excel文件(*.xls),*.xls", _MultiSelect:=True, Title:="要合并的文件")If TypeName(FilesToOpen) = "Boolean" ThenMsgBox "没有选中文件"GoTo ExitHandlerEnd Ifx = 1While x <= UBound(FilesToOpen)Workbooks.Open Filename:=FilesToOpen(x)Sheets().Move after:=ThisWorkbook.Sheets _(ThisWorkbook.Sheets.Count)x = x + 1WendExitHandler:Application.ScreenUpdating = TrueExit SubErrHandler:MsgBox Err.DescriptionResume ExitHandlerEnd Sub