1、将需合并的Excel文件放在同一个文件夹中。
2、打开新建的Excel文件,按 Alt + F11 键,打开宏,选择视图→代码窗口。
3、将下面的代码拷贝粘贴到代码窗口中:
Sub sheets2one()
'定义对话框变量
Dim cc As FileDialog
Set cc = Application.FileDialog(msoFileDialogFilePicker)
Dim newwork As Workbook
Set newwork = Workbooks.Add
With cc
If .Show = -1 Then
Dim vrtSelectedItem As Variant
Dim i As Integer
i = 1
For Each vrtSelectedItem In .SelectedItems
Dim tempwb As Workbook
Set tempwb = Workbooks.Open(vrtSelectedItem)
tempwb.Worksheets(1).Copy Before:=newwork.Worksheets(i)
newwork.Worksheets(i).Name = VBA.Replace(tempwb.Name, ".xls", "")
tempwb.Close SaveChanges:=False
i = i + 1
Next vrtSelectedItem
End If
End With
Set cc = Nothing
End Sub