快速汇总多个工作表,如何将Excel中多个不同的工作表汇总成一张总表
答案:1 悬赏:20 手机版
解决时间 2021-04-23 07:03
- 提问者网友:风月客
- 2021-04-22 23:10
快速汇总多个工作表,如何将Excel中多个不同的工作表汇总成一张总表
最佳答案
- 五星知识达人网友:污到你湿
- 2021-04-23 00:46
把要合并的文件复制到一个新建文件夹中,在该文件夹中新建一个execl,仅打开新建Excel,按Alt+F11,点菜单的插入,模块,粘贴如下代码:
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 + 2, 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
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 + 2, 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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯