View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
et10yl et10yl is offline
external usenet poster
 
Posts: 8
Default 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