如何快速將多個excel表格的全部sheet合併到一個sheet中

一、將須要合併的excel文件放在同一個文件夾下;html

二、新建一個excel表格並打開,右鍵sheet1,查看代碼,而後複製下方的代碼到代碼框裏,點擊菜單欄中的「運行」–「運行子過程/用戶窗體」,等待程序運行結束,便可實現數據合併到sheet1中。oop

詳細步驟可參考:https://jingyan.baidu.com/article/f0062228d16ba9fbd3f0c82b.html?qq-pf-to=pcqq.c2cexcel

 

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 Suborm

相關文章
相關標籤/搜索