Hello,
What I am trying to do is to open the excel file with the biggest date in the folder. The way my code works and breaks is that it subtracts one day from business day. The thing is if on Monday I run my code and no file was available on Friday my code breaks. I just need help finding the file with the biggest date.
If we have two files
My title 06-27
My title 06-28
I want to open 06-28 automatically since 28 is the file with the biggest date.
Below is the code I am currently using
Dim fpath4 As String: fpath4 = "link to the website"
Dim fName4 As String
Dim xWs4 As Worksheet
Dim wb4 As Workbook
Set wb4 = ActiveWorkbook
BD = CDate(Evaluate("WORKDAY(TODAY(),-1)"))
BD = Format(BD, "mm-dd")
fName4 = Format(Date, "mm-dd")
fName4 = "Title Here " & BD & ".xlsx"
monthAndYear = Format(Date, "mmmm" & " " & "yyyy")
fName4 = fpath4 & monthAndYear & "" & fName4
currentFile = ThisWorkbook.Name
Set wb4 = Workbooks.Open(fName4)
Set wb4 = ActiveWorkbook
Set ws4 = wb4.ActiveSheet
What I am trying to do is to open the excel file with the biggest date in the folder. The way my code works and breaks is that it subtracts one day from business day. The thing is if on Monday I run my code and no file was available on Friday my code breaks. I just need help finding the file with the biggest date.
If we have two files
My title 06-27
My title 06-28
I want to open 06-28 automatically since 28 is the file with the biggest date.
Below is the code I am currently using
Dim fpath4 As String: fpath4 = "link to the website"
Dim fName4 As String
Dim xWs4 As Worksheet
Dim wb4 As Workbook
Set wb4 = ActiveWorkbook
BD = CDate(Evaluate("WORKDAY(TODAY(),-1)"))
BD = Format(BD, "mm-dd")
fName4 = Format(Date, "mm-dd")
fName4 = "Title Here " & BD & ".xlsx"
monthAndYear = Format(Date, "mmmm" & " " & "yyyy")
fName4 = fpath4 & monthAndYear & "" & fName4
currentFile = ThisWorkbook.Name
Set wb4 = Workbooks.Open(fName4)
Set wb4 = ActiveWorkbook
Set ws4 = wb4.ActiveSheet