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

2025-02-24 10:42:53
推荐回答(3个)
回答1:

将多个Excel文件合并为一个Excel文件
步骤:宏--创建--输入下面内容:
Sub CombineWorkbooks()
Dim FilesToOpen
Dim x As Integer

On Error GoTo ErrHandler
Application.ScreenUpdating = False

FilesToOpen = Application.GetOpenFilename _
(FileFilter:="MicroSoft Excel文件(*.xls),*.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:
MsgBox Err.Description
Resume ExitHandler
End Sub

回答2:

用宏试试。

回答3:

100个文件,每个文件只要第1个工作表吗?