1.需要把多個excel表都放在同一個資料夾裡面,並在這個資料夾裡面新建一個excel。如圖所示: 2.用microsoft excel開啟新建的excel表,並右鍵單擊sheet1,找到“檢視程式碼”,單擊進去。進去之後就看到了宏計算介面。如圖所示: 3.然後把下面這些宏計算的程式碼複製進去,然後找到工具欄上面的“執行”下的“執行子過程/使用者窗體”,程式碼如下,如圖所示: 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("B65536").End(xlUp)
.Row
+ 2, 1) = Left(MyName, Len(MyName) - 4) For G = 1 To
Sheets.Count
Wb.Sheets(G)
.UsedRange.Copy
.Cells(.Range("B65536").End(xlUp)
.Row
+ 1, 1) Next WbN = WbN & Chr(13) &
Wb.Name
Wb.Close
False End With End If MyName = Dir Loop Range("B1")
.Select
Application.ScreenUpdating
= True MsgBox "共合併了" & Num & "個工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示" End Sub 4.執行之後,等待10秒針左右,等執行完畢,就是合併完成之後,會有提示,點確定就可以了。檢視合併後的資料,有5000多行,就是同一個資料夾裡面17個excel表資料合併後的結果。效果如圖所示。
1.需要把多個excel表都放在同一個資料夾裡面,並在這個資料夾裡面新建一個excel。如圖所示: 2.用microsoft excel開啟新建的excel表,並右鍵單擊sheet1,找到“檢視程式碼”,單擊進去。進去之後就看到了宏計算介面。如圖所示: 3.然後把下面這些宏計算的程式碼複製進去,然後找到工具欄上面的“執行”下的“執行子過程/使用者窗體”,程式碼如下,如圖所示: 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("B65536").End(xlUp).Row
+ 2, 1) = Left(MyName, Len(MyName) - 4) For G = 1 ToSheets.Count
Wb.Sheets(G).UsedRange.Copy
.Cells(.Range("B65536").End(xlUp).Row
+ 1, 1) Next WbN = WbN & Chr(13) &Wb.Name
Wb.Close
False End With End If MyName = Dir Loop Range("B1").Select
Application.ScreenUpdating
= True MsgBox "共合併了" & Num & "個工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示" End Sub 4.執行之後,等待10秒針左右,等執行完畢,就是合併完成之後,會有提示,點確定就可以了。檢視合併後的資料,有5000多行,就是同一個資料夾裡面17個excel表資料合併後的結果。效果如圖所示。