Professional Documents
Culture Documents
I was wondering if you could help with the following query please.
At the moment my code below works well when I have files only in the main folder called
"E:\Dian\Test". (Reads only files copied in the main folder (MyPath) but not the files in
the subfolder)
You will see I added the question in inverted commas (in green) in the code below.
Thank you :)
'How do you include a loop to include searching through SubFolders, within the
E:\Dian\Test folder, for xlsx files starting with the name
"out_*"??????????????????????????????????????'
MyPath = "E:\Dian\Test\"
' Fill the myFiles array with the list of Excel files
' in the search folder.
Fnum = 0
Do While FilesInPath <> ""
If FilesInPath <> ActiveWorkbook.Name Then
Fnum = Fnum + 1
ReDim Preserve myFiles(1 To Fnum)
myFiles(Fnum) = FilesInPath
End If
FilesInPath = Dir()
Loop
End If
FirstCell = "A4"
Set sourceRange = .Range(FirstCell & ":" & RDB_Last(3, .Cells))
' Test if the row of the last cell is equal to or greater than the row of the first cell.
If RDB_Last(1, .Cells) < .Range(FirstCell).Row Then
Set sourceRange = Nothing
End If
End With
If Err.Number > 0 Then
Err.Clear
Set sourceRange = Nothing
Else
' If source range uses all columns then
' skip this file.
If sourceRange.Columns.Count >= BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0
SourceRcount = sourceRange.Rows.Count
End With
End With
destrange.Value = sourceRange.Value
Next Fnum
BaseWks.Columns.AutoFit
End If