Locating Latest Workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Which command do I use to locate the latest workbook in A Folder,
I have a series of Excel workbooks, they are named by the date they were saved
i.e. List 01-12-04
List 08-12-04
List 15-12-04 etc.etc.
 
Hi

Function LatestFile(Folder As String, _
sType As String) As String
Dim Dt As Date
Dim NextFile As String
NextFile = Dir(Folder & "\" & sType)
Do Until NextFile = ""
If FileDateTime(Folder & "\" & NextFile) > Dt Then _
LatestFile = NextFile
NextFile = Dir()
Loop
End Function

Sub test()
MsgBox LatestFile("C:\Temp", "*.*")
MsgBox LatestFile("C:\Temp", "*.rtf")
MsgBox LatestFile("C:\Temp", "*.xl*")
End Sub

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top