如何将多个excel文件导入到一个excel中,生成不同的工作表

2024-11-08 06:03:19
推荐回答(3个)
回答(1):

使用这段VB吧,生成的工作表名是按原表名+1.2.3.4.5这样来的.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):

在excel文件 左下方有三个这个东西,点击插入,生成一个新的表格,在新的表格里面打开你所需要的另一个excel表。~

回答(3):

使用这段VB吧,生成的工作表名是按原表名+1.2.3.4.5这样来的.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