#1
|
|||
|
|||
Need help opening the most recent file of download folder
My routine work in Excel is such that I should constantly download some data from some websites and saving each data in different folders. After downloading, the data files are saved in download folder. When downloading files with the same name in different days, the files are saved with ' (1)', ' (2)', etc. added to their name. Now I want to have a code to open the most recent file of specific data. I have written the following code to do so, but it fails (based on attached screenshot, the code is expected to open "statement (7).xls" but it opens the "statement.xls"). Can you give me some guides on this issue?
Option Explicit Sub Opendownload() Dim MyPath As String Dim MyFile As String Dim myfilename As String Dim myfilename02 As String Dim Nmyfile As String Dim n As String Dim temp As String 'Specify the path to the folder MyPath = "C:\Users\s.kalantari\Downloads" myfilename = "statement" Nmyfile = Len(myfilename) 'Make sure that the path ends in a backslash If Right(MyPath, 1) <> "" Then MyPath = MyPath & "" MyFile = Dir(MyPath & "*.xls", vbNormal) temp = 0 Do While Len(MyFile) > 0 And Mid(MyFile, 1, Nmyfile) = myfilename 'by n I expect to extract 1,2,etc from (1), (2), etc n = Mid(MyFile, Nmyfile + 3, 1) If n > temp Then temp = n myfilename02 = MyFile End If |
#2
|
||||
|
||||
Date modified is showing that statement.xls is the most recent file in that file set.
Do you want the last saved file or the one with the biggest number in brackets?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
By “most recent file” I mean the most recent file concerning the time in it the file is downloaded not the time in it the file is saved, so I want the one with the biggest number in brackets.
Last edited by soroush.kalantari; 09-12-2022 at 03:22 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Recent Office Update causing issues opening older Excel worksheet | jasonbrod | Excel | 6 | 12-17-2021 03:43 PM |
Word file says 'Opening in Protected View' but not opening. | Yakbird | Word | 2 | 07-08-2019 10:55 AM |
Can't Find Word Document in Search or in Folder But It's There in Recent Documents | CrossReach | Word | 1 | 10-14-2016 01:27 PM |
Problem opening Outlook Today. Error Message: Cannot display the folder. Cannot find this file. Veri | atwnsw | Outlook | 0 | 11-01-2015 05:05 PM |
Download Public Folder Favorites registry key | Rapture | Outlook | 1 | 02-09-2015 12:19 PM |