Hello,
I got this code fromm mslynng (the original posts: http://excel.bigresource.com/Track/excel-8Zjqhjv0/) and I have to say I love this code a lot.. problem is that it only seems to copy just six xls files.. I have a 60+ xls files both containing pdf and excel. But the code can ignore the pdf.. i just need the excel. Anyway, I tried to change the code but, obviously, nothing works.. hope your help here.
Thanks!
here's the code:
[code]
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 = ActiveWorkbook.Path 'Change as needed
Filename = Dir(Path & "\*.xls", vbNormal)
Do Until Filename = ""
If Filename <> ThisWorkbook.Name 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()
Else: Filename = ""
End If
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Sheets("Master").Select
Dim r As Long
'Turn screen updates off to make things look nicer
Application.ScreenUpdating = False
'Delete everything in Master sheet, from row 2 downwards
Sheets("Master").UsedRange.Offset(1).Clear
'Loop through all worksheets
For Each ws In ActiveWorkbook.Worksheets
'Do this for all sheets except the Master sheet
If ws.Name <> "Master" Then
'Copy from 4th row and downwards
ws.Range("A1:IV" & ws.Range("A65536").End(xlUp).Row).Copy
'Paste values to Master sheet, below last used row
Sheets("Master").Range("A" & Sheets("Master").Range("A65536").End(xlUp).Row + 1).PasteSpecial xlPasteValues
'Cells(ActiveSheet.UsedRange.Rows.Count + 2, 1).PasteSpecial xlPasteValues
End If
Next ws
'Remove completely empty rows
'For r = Sheets("Master").UsedRange.Rows.Count To 1 Step -1
'If Application.WorksheetFunction.CountA(Rows(r)) = 0 Then
'Sheets("Master").Rows(r).Delete
'End If
'Next r
Dim t As Double
t = Sheets("Master").Range("A65536").End(xlUp).Row
For r = 1 To t
If Sheets("Master").Range("A" & r).Value = "" Then
Sheets("Master").Rows(r).Delete
t = t - 1
End If
Next r
'Select cell A1
Range("A1").Select
'Turn after-copy-blinking off
Application.CutCopyMode = False
'Turn screen updates back on
Application.ScreenUpdating = True
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name <> "Master" And ws.Name <> "" Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub
Bookmarks