therealjdj
New Member
- Joined
- Jul 8, 2013
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hey everyone,
I am trying to combing multiple excel files into one larger file. Each original file only has one tab. I have searched and found code to do this, however each solution ends up with tabs names Sheet 1, Sheet 1 (2), Sheet 1 (3),...
I really need the tabs to be named per the original file names.
Here is the code I have. What do I need to add to automatically rename the tabs when they are created using the original file name? Thank you!!
I am trying to combing multiple excel files into one larger file. Each original file only has one tab. I have searched and found code to do this, however each solution ends up with tabs names Sheet 1, Sheet 1 (2), Sheet 1 (3),...
I really need the tabs to be named per the original file names.
Here is the code I have. What do I need to add to automatically rename the tabs when they are created using the original file name? Thank you!!
Code:
Sub MergeMe()
Dim Path As String
Dim Filename As String
Dim Sheet As Worksheet
Path = "C:\Data"
Filename = Dir(Path & "*.xlsx")
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