So I do a seach in a directory to find the newest file that has been downloaded into the directory. Once that file has been identified, it is opened and processed into my workbook. If for some reason I download an incorrect file into the directory, it obviously screws with my process workbook. (Just happened) If I can identify an incorrect file before processing I can stop the code from finishing.
I'd like to be able to name this newest file before processing so I can run a test to see if it's the correct file file. I have another macro that processes the opened WB. If I have a name for this opened file, I can reference it in my "TestMe" macro. I may need to name it before opening, but after it has been identified as the newewst file.
Finally, maybe I have the wrong idea completely and would welcome a different approach. Thanks so much for all the help you folks provide.
I'd like to be able to name this newest file before processing so I can run a test to see if it's the correct file file. I have another macro that processes the opened WB. If I have a name for this opened file, I can reference it in my "TestMe" macro. I may need to name it before opening, but after it has been identified as the newewst file.
Finally, maybe I have the wrong idea completely and would welcome a different approach. Thanks so much for all the help you folks provide.
VBA Code:
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate = 0 Then GoTo finish
If LMD > LatestDate > 0 Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
Workbooks.Open MyPath & LatestFile
' TestMe Newest file is opened waiting to be used. I'd like to test it before processing.
ActiveWorkbook.Activate
Exit Sub