View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sandy Sandy is offline
external usenet poster
 
Posts: 355
Default Open most recent file

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!