ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locating Latest Workbook (https://www.excelbanter.com/excel-programming/318814-locating-latest-workbook.html)

Teresa

Locating Latest Workbook
 
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.
So Far I have

sub fold()

dim i

i = C:\My Documents\Workbooks.Count
MsgBox C:\My Documents\Workbooks(i)

End Sub



Harald Staff

Locating Latest Workbook
 
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

"teresa" skrev i melding
...
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.
So Far I have

sub fold()

dim i

i = C:\My Documents\Workbooks.Count
MsgBox C:\My Documents\Workbooks(i)

End Sub






All times are GMT +1. The time now is 01:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com