S
Sandy
Hello
I am trying to open the most recent file in a folder. I have found 2
possible solutions here but neither seem to work for me.
First:
Const FilePath = "Mypath"
Workbooks.Open Filename:=FindNewestFile(FilePath)
This one gives me Undefined sub or function on
FindNewestFile
The other:
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.Filename = "*.jnk"
.Execute SortBy:=msoSortBySize
.NewSearch
.LookIn = "mypath"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute(SortBy:=msoSortByLastModified,
SortOrder:=msoSortOrderDescending) > 0 Then
MsgBox "The newest file is " & .FoundFiles(1) & " created " &
FileDateTime(.FoundFiles(1))
Workbooks.Open .FoundFiles(1)
Else
MsgBox "There were no files found."
End If
End With
This one gives me "Object doesn't support this action" on
With Application.FileSearch
Can anyone help?
Thanks!
I am trying to open the most recent file in a folder. I have found 2
possible solutions here but neither seem to work for me.
First:
Const FilePath = "Mypath"
Workbooks.Open Filename:=FindNewestFile(FilePath)
This one gives me Undefined sub or function on
FindNewestFile
The other:
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.Filename = "*.jnk"
.Execute SortBy:=msoSortBySize
.NewSearch
.LookIn = "mypath"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute(SortBy:=msoSortByLastModified,
SortOrder:=msoSortOrderDescending) > 0 Then
MsgBox "The newest file is " & .FoundFiles(1) & " created " &
FileDateTime(.FoundFiles(1))
Workbooks.Open .FoundFiles(1)
Else
MsgBox "There were no files found."
End If
End With
This one gives me "Object doesn't support this action" on
With Application.FileSearch
Can anyone help?
Thanks!