Hi ,
I have a folder with different files, updated every week. One file is added per week.
I need a VBA code which take the name of the most recent file and the 4rth one based on the date founded in the file name in the format "YYYY-Month-DD Targets - ALL.xls", eg. "2023-Apr-24 BDD Targets - ALL.xls".
Could someone help? This below part of my code..
Thanks a lot.
I have a folder with different files, updated every week. One file is added per week.
I need a VBA code which take the name of the most recent file and the 4rth one based on the date founded in the file name in the format "YYYY-Month-DD Targets - ALL.xls", eg. "2023-Apr-24 BDD Targets - ALL.xls".
Could someone help? This below part of my code..
VBA Code:
For Each objfile In myFolder.Files
If InStr(1, objfile.Name, ".xls") > 0 Then
i = i + 1
fileName = objfile.Name
dateParts = Split(fileName, "-")
yearPart = dateParts(0)
monthPart = Month(DateValue(dateParts(1) & " 1, 2021")) ' Convert month name to number
dayPart = Left(dateParts(2), 2)
dateStr = DateSerial(yearPart, monthPart, dayPart)
Thanks a lot.