Littlemalky
Board Regular
- Joined
- Jan 14, 2011
- Messages
- 223
I need to be able to open files in a folder from the previous month rather than the current month. I have code that does the current month, how do I tweak this to adjust for that change? The exact path is this:
Here is the code I have for opening the file currently:
Code:
G:\Inventory Control\Monthly Fulfillment reports\2011 Monthly Fulfillments\4-2011
Code:
Sub Open
Dim dirName As String, Fname As String, FileTime As Date, Filename As String, LatestFile As String
dirName = "G:\Inventory Control\Monthly Fulfillment reports\" & Format(Date, "yyyy") & " Monthly Fulfillments\" & Format(Date, "mm-yyyy") & "\"
Fname = Dir(dirName & "*.xlsx")
LatestFile = Fname
FileTime = FileDateTime(dirName & Fname)
While Fname <> ""
If FileDateTime(dirName & Fname) > FileTime Then
LatestFile = Fname
FileTime = FileDateTime(dirName & Fname)
End If
Fname = Dir()
Wend
If LatestFile = "" Then
MsgBox "There are no files in the directory"
Else
Workbooks.Open dirName & LatestFile, UpdateLinks:=0
End If
End Sub