Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 124
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, 12 views)
Attached Files
File Type: xlsm opendownload.xlsm (18.9 KB, 4 views)
Reply With Quote
 



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 07:27 AM.


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