Hi,
This is my basic template to search through a specific file type within a folder.
However, while using this, and there could be up to 100 workbooks per folder. And as my title suggests I would like the "search" through these files to start with the files most recently modified. From what I can tell, it starts with the "oldest" files within the folders at the moment.
Does anyone know if this is at all possible, and if it is, how to amend my "search"?
If anything is unclear, please let me know and I will try to clarify.
EDIT: In the specific case that made me want this change, I want to search all cells within a wbk for a specific value. If a solution for this is easily available, I'm all ears. I'm mainly thinking speed of the search.
This is my basic template to search through a specific file type within a folder.
Code:
ChDir ("Your Directory Here")
'Selecting a folder to search through.
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
If .SelectedItems.Count = 0 Then
MsgBox "You did not select a folder"
Exit Sub
End If
fPath = .SelectedItems(1) & "\"
End With
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
fName = Dir(fPath & "*.xlsx") 'alternatives, .xlsm, . txt etc...
Do
fName = Dir
If fName = "" Then
Exit Sub
End If
Set wbk = Workbooks.Open(fPath & fName)
'Macro while in workbook
wbk.close
Loop While fName <> ""
However, while using this, and there could be up to 100 workbooks per folder. And as my title suggests I would like the "search" through these files to start with the files most recently modified. From what I can tell, it starts with the "oldest" files within the folders at the moment.
Does anyone know if this is at all possible, and if it is, how to amend my "search"?
If anything is unclear, please let me know and I will try to clarify.
EDIT: In the specific case that made me want this change, I want to search all cells within a wbk for a specific value. If a solution for this is easily available, I'm all ears. I'm mainly thinking speed of the search.
Last edited: