Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2022, 08:02 PM
soroush.kalantari soroush.kalantari is offline Need help opening the most recent file of download folder Windows 10 Need help opening the most recent file of download folder Office 2016
Competent Performer
Need help opening the most recent file of download folder
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default 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
Attached Images
File Type: png download_folder.PNG (47.3 KB, 10 views)
Attached Files
File Type: xlsm opendownload.xlsm (18.9 KB, 2 views)
Reply With Quote
  #2  
Old 09-11-2022, 03:12 PM
Guessed's Avatar
Guessed Guessed is offline Need help opening the most recent file of download folder Windows 10 Need help opening the most recent file of download folder Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-11-2022, 07:26 PM
soroush.kalantari soroush.kalantari is offline Need help opening the most recent file of download folder Windows 10 Need help opening the most recent file of download folder Office 2016
Competent Performer
Need help opening the most recent file of download folder
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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?
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.
Reply With Quote
Reply

Thread Tools
Display Modes


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
Need help opening the most recent file of download folder 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft