如何快速将多个excel表格的所有sheet合并到一个sheet中

1、将需要合并的excel文件放在同一个文件夹下;

2、新建一个excel表格并打开,右键sheet1,查看代码,然后复制下方的代码到代码框里,点击菜单栏中的“运行”–“运行子过程/用户窗体”,等待程序运行结束,即可实现数据合并到sheet1中。

详细步骤可参考:https://jingyan.baidu.com/article/f0062228d16ba9fbd3f0c82b.html?qq-pf-to=pcqq.c2c

 

Sub 合并当前目录下所有工作簿的全部工作表()
Dim mypath, myname, awbname
Dim wb As Workbook, wbn As String
Dim g As Long
Dim num As Long
Dim box As String
Application.ScreenUpdating = False
mypath = ActiveWorkbook.Path
myname = Dir(mypath & “\” & “*.xls”)
awbname = ActiveWorkbook.Name
num = 0
Do While myname <> “”
If myname <> awbname Then
Set wb = Workbooks.Open(mypath & “\” & myname)
num = num + 1
With Workbooks(1).ActiveSheet
.Cells(.Range(“a65536”).End(xlUp).Row + 1, 1) = Left(myname, Len(myname) – 4)
For g = 1 To Sheets.Count
wb.Sheets(g).UsedRange.Copy .Cells(.Range(“a65536”).End(xlUp).Row + 1, 1)
Next
wbn = wbn & Chr(13) & wb.Name
wb.Close False
End With
End If
myname = Dir
Loop
Range(“a1”).Select
Application.ScreenUpdating = True
MsgBox “共合并了” & num & “个工作薄下的全部工作表。如下:” & Chr(13) & wbn, vbInformation, “提示”
End Sub

posted @ 2019-11-09 20:59  诗酒*趁年华  阅读(26885)  评论(0编辑  收藏  举报