Cách gộp nhiều file Excel thành 1 file nhiều sheet

Bạn có rất nhiều file excel rời rạc, bạn muốn gộp tất cả các file excel này lại thành 1 file excel có nhiều sheet nhưng bây giờ mà mở từng file lên và copy sheet thì đúng là cực hình.

Các bạn có thể thực hiện việc này tự động bằng Visual Basic, không tốn quá nhiều công

Sub ConslidateWorkbooks()
'Created by Sumit Bansal from https://trumpexcel.com
Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = "E:\Desktop\gop-sheet\"
Filename = Dir(FolderPath & ".xls")
Do While Filename <> ""
Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.ScreenUpdating = True
End Sub

Quảng cáo

Ủng hộ website

Add Comment