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

如题所述

使用这段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
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-07-15
在excel文件 左下方有三个这个东西,点击插入,生成一个新的表格,在新的表格里面打开你所需要的另一个excel表。~
第2个回答  2019-09-20
使用这段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
相似回答