Hello all,
I'm attempting to write a script to open up the most current Excel spreadsheet once it has been placed into a specific folder. I've run into a compiling issue when I attempt to run my code.
Any and all help is always appreciated.
D.
I'm attempting to write a script to open up the most current Excel spreadsheet once it has been placed into a specific folder. I've run into a compiling issue when I attempt to run my code.
Rich (BB code):
Sub OpenMostRecent()
Dim fs As String, ws As Worksheet, i As Long
Dim loc As Long, fdt As Double
Set fs = "C:\Users\WindowsUser\Desktop\VBA Code Files"
With fs
.SearchSubFolders = False ' set to true if you want sub-folders included
.FileType = msoFileTypeExcelWorkbooks
.LookIn = Dir("C:\Users\WindowsUser\Desktop\VBA Code Files")
If .Execute > 0 And .FoundFiles.Count > 0 Then
loc = 0
For i = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(i)) > fdt Then loc = i
Next i
Workbooks.Open .FoundFiles(loc)
Else
MsgBox "No files found"
End If
End With
End Sub
D.
Last edited by a moderator: