Combine Workbooks with Same Prefix into One New Workbook

E

et10yl

I have a folder with several hundred workbooks. Some workbooks have the same
prefix. I'd like to combine all the worksheets from workbooks with the same
prefix into one workbook, and save this combined workbook as a new workbook.
I tried using this but it doesn't seem to work. Also, I had programmed a
user form to get the value of the prefix, but it doesn't seem to be passing
the value to the Module? Any help would be appreciated. Thanks!

Sub CombineFiles()
Dim prefix as String

Do Until FileName = ""

If FileName = Dir(Path & "\" & prefix & "*.xls", vbNormal) Then

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()

End If
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top