Originally Posted by
Tinbendr
Replace the sub with this one.
This creates a "WorkBook name-Sheet Name" sheet name, because if you have more than one sheet, it will fail using only the source workbook name.
[vba]Sub CombineFiles()
Dim path As String
Dim FileName As String
Dim LastCell As Range
Dim Wkb As Workbook
Dim ws As Worksheet
Dim ThisWB As String
Dim ShtName As String
Dim ExtPos As Long
ThisWB = ThisWorkbook.Name
Application.EnableEvents = False
Application.ScreenUpdating = False
path = GetDirectory
FileName = Dir(path & "\*.xls", vbNormal)
Do Until FileName = ""
If FileName <> ThisWB Then
Set Wkb = Workbooks.Open(FileName:=path & "\" & FileName)
For Each ws In Wkb.Worksheets
Set LastCell = ws.Cells.SpecialCells(xlCellTypeLastCell)
If LastCell.Value = "" And LastCell.Address = Range("$A$1").Address Then
Else
ws.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
'Locate the last period in filename by reversing the string.
ExtPos = InStr(StrReverse(Wkb.Name), ".")
'Strip the extension. Accounts for any length extension.
ShtName = Mid(Wkb.Name, 1, Len(Wkb.Name) - ExtPos) & "-" & ws.Name
'Rename the new sheet to Imported WB and Sheet names
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = ShtName
End If
Next ws
Wkb.Close False
End If
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Set Wkb = Nothing
Set LastCell = Nothing
End Sub[/vba]