ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combine Workbooks with Same Prefix into One New Workbook (https://www.excelbanter.com/excel-programming/377156-combine-workbooks-same-prefix-into-one-new-workbook.html)

et10yl

Combine Workbooks with Same Prefix into One New Workbook
 
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.Cou nt)
Next WS
Wkb.Close False
FileName = Dir()

End If
Loop
End Sub


All times are GMT +1. The time now is 10:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com