Hi All,
I must say, I've received so much help throughout the years on this forum, that I am greatful.
I have a new question that I'm hoping someone can help me with. I have to combine multiple workbooks, each have one spreadsheet and all in one directory, where I'm taking workbooks with a similar naming scheme and placing them in a new workbook. For example:
If I had workbook-1, workbook-2, and workbook-3, I would like to take these workbooks and combine into a new workbook titled lets say "Workbook" with workbook-1, workbook-2, and workbook-3 each having their own tab/spreadsheet in the new workbook "Workbook".
Also, if I had the following workbooks: sp-1, sp-2, and sp-3, I would like to combine these into a new workbook titled "SP" each having its own spreadsheet in the new workbook "SP". Each spreadsheet in "SP" should be titled SP-1, SP-2, and SP-3 respectively.
The problem is that there are a few hundred of these and I'm not sure how to attack this merge. Any thoughts? I have the code for a basic merge into one workbook (From a previous VBAX posting), but I don't know how to create separate workbooks based on the naming scheme. Any help would be greatly appreciated.
Here's what I have for a basic single workbook merge.
[vba]Option Explicit
Sub CombineFiles()
Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim WS As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
Path = "C:\" 'Change as needed
FileName = Dir(Path & "\*.xls", vbNormal)
Do Until FileName = ""
Set Wkb = Workbooks.Open(FileName:=Path & "\" & FileName)
For Each WS In Wkb.Worksheets
WS.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next WS
Wkb.Close False
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub[/vba]