Beruflich Dokumente
Kultur Dokumente
Formulae No - 01
Formulae Name : VBA Code "Sub GetSheets()"
Use Full for : You can use VBA scripts to combine multiple workbook into one master workbook
_______________________________________________________________________________________
Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be
displayed, click Insert > Module, and input the following code into the Module:
Sub GetSheets()
Path = "C:\Users\dt\Desktop\dt kte\"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub
___________________________________________________________________________________________________
Tip: In the above code, you can change the path to the one that you are using.
Then click button to run the code, and all of the worksheets (including the blank worksheets
within the workbooks have been merged into the master workbook.
Note: This VBA code can merge the entire workbooks into the master workbook, if you want to
combine specified worksheets of the workbooks, this code will not work.
Sub MakeSummaryTable()
Dim ws As Worksheet
Application.ScreenUpdating = False
Sheets("Sheet1").Activate
Application.ScreenUpdating = True
End Sub
Sub SortWorkBook()
'Updateby20140624
Dim xResult As VbMsgBoxResult
xTitleId = "KutoolsforExcel"
xResult = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) & "Clicking No will sort
in Descending Order", vbYesNoCancel + vbQuestion + vbDefaultButton1, xTitleId)
For i = 1 To Application.Sheets.Count
For j = 1 To Application.Sheets.Count - 1
If xResult = vbYes Then
If UCase$(Application.Sheets(j).Name) > UCase$(Application.Sheets(j +
1).Name) Then
Sheets(j).Move after:=Sheets(j + 1)
End If
ElseIf xResult = vbNo Then
If UCase$(Application.Sheets(j).Name) < UCase$(Application.Sheets(j +
1).Name) Then
Application.Sheets(j).Move after:=Application.Sheets(j + 1)
End If
End If
Next
Next
End Sub