View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Hutchins Tom Hutchins is offline
external usenet poster
 
Posts: 1,069
Default Open latest file

Maybe something like

Sub AAAAA()
'Call FindNewestFile. Tell it the path & the file name pattern.
MsgBox FindNewestFile("D:\Tom's Files\", "File*.xls")
End Sub

Private Function FindNewestFile(MyPath As String, MyFile As String) As String
Dim LastDate As Date, NewDate As Date
Dim LastFile As String, NewFile As String
LastFile$ = LCase$(Dir(MyPath$ & MyFile$))
LastDate = FileDateTime(MyPath$ & LastFile$)
NewFile$ = LastFile$
Do While Len(NewFile$) 0
NewFile$ = LCase$(Dir())
If Len(NewFile$) = 0 Then Exit Do
NewDate = FileDateTime(MyPath$ & NewFile$)
If NewDate LastDate Then
LastDate = NewDate
LastFile$ = NewFile$
End If
Loop
FindNewestFile = LastFile$
End Function

Hope this helps,

Hutch

"Bigfoot17" wrote:

I usually don't do as well with questions asked on Friday, but I need to
anyway.

I have one user adding files to a folder using a common name and date scheme:
"File 012909.xls"
"File 020509.xls"
"File 021209.xls"
"File 021909.xls" etc.

What I have been setting up is a control panel for a user so they do not
need to mess with lengthy pathnames etc. I would like to be able to click a
button on the control panel to open the latest version of "File" in the
folder. Any suggestions?