Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I use code below to find the latest modified file in a directory. How can
can do that same thing an also set criteria to look for latest file modified beginning with "aaa*" . . . how to get newest "C:\Lee\" & "aaa*" Dim fNewest Set oFolder = CreateObject("scripting.filesystemobject").getfold er("C:\Lee\") For Each aFile In oFolder.Files If fNewest = "" Then Set fNewest = aFile Else If fNewest.DateLastModified < aFile.DateLastModified Then Set fNewest = aFile End If End If Next MsgBox fNewest.Name -- Thanks & Best Regards |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try the below function...
Sub Macro() MsgBox GetLatestFileName("c:\test") MsgBox GetLatestFileName("c:\test", "ba*.txt") End Sub Function GetLatestFileName(strFolder As String, Optional strFilter As String) Dim strFile As String, varDT As Variant strFile = Dir(strFolder & "\" & strFilter, vbNormal) Do While strFile < "" If FileDateTime(strFolder & "\" & strFile) varDT Then varDT = FileDateTime(strFolder & "\" & strFile) GetLatestFileName = strFile End If strFile = Dir Loop End Function -- Jacob (MVP - Excel) "LeeL" wrote: I use code below to find the latest modified file in a directory. How can can do that same thing an also set criteria to look for latest file modified beginning with "aaa*" . . . how to get newest "C:\Lee\" & "aaa*" Dim fNewest Set oFolder = CreateObject("scripting.filesystemobject").getfold er("C:\Lee\") For Each aFile In oFolder.Files If fNewest = "" Then Set fNewest = aFile Else If fNewest.DateLastModified < aFile.DateLastModified Then Set fNewest = aFile End If End If Next MsgBox fNewest.Name -- Thanks & Best Regards |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks! Nice and clean way to to do it!
-- Thanks & Best Regards "Jacob Skaria" wrote: Try the below function... Sub Macro() MsgBox GetLatestFileName("c:\test") MsgBox GetLatestFileName("c:\test", "ba*.txt") End Sub Function GetLatestFileName(strFolder As String, Optional strFilter As String) Dim strFile As String, varDT As Variant strFile = Dir(strFolder & "\" & strFilter, vbNormal) Do While strFile < "" If FileDateTime(strFolder & "\" & strFile) varDT Then varDT = FileDateTime(strFolder & "\" & strFile) GetLatestFileName = strFile End If strFile = Dir Loop End Function -- Jacob (MVP - Excel) "LeeL" wrote: I use code below to find the latest modified file in a directory. How can can do that same thing an also set criteria to look for latest file modified beginning with "aaa*" . . . how to get newest "C:\Lee\" & "aaa*" Dim fNewest Set oFolder = CreateObject("scripting.filesystemobject").getfold er("C:\Lee\") For Each aFile In oFolder.Files If fNewest = "" Then Set fNewest = aFile Else If fNewest.DateLastModified < aFile.DateLastModified Then Set fNewest = aFile End If End If Next MsgBox fNewest.Name -- Thanks & Best Regards |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can the function include way to get other attributes such as: Datecreated,
DateLastModified, and DateLastAccessed? -- Thanks & Best Regards "Jacob Skaria" wrote: Try the below function... Sub Macro() MsgBox GetLatestFileName("c:\test") MsgBox GetLatestFileName("c:\test", "ba*.txt") End Sub Function GetLatestFileName(strFolder As String, Optional strFilter As String) Dim strFile As String, varDT As Variant strFile = Dir(strFolder & "\" & strFilter, vbNormal) Do While strFile < "" If FileDateTime(strFolder & "\" & strFile) varDT Then varDT = FileDateTime(strFolder & "\" & strFile) GetLatestFileName = strFile End If strFile = Dir Loop End Function -- Jacob (MVP - Excel) "LeeL" wrote: I use code below to find the latest modified file in a directory. How can can do that same thing an also set criteria to look for latest file modified beginning with "aaa*" . . . how to get newest "C:\Lee\" & "aaa*" Dim fNewest Set oFolder = CreateObject("scripting.filesystemobject").getfold er("C:\Lee\") For Each aFile In oFolder.Files If fNewest = "" Then Set fNewest = aFile Else If fNewest.DateLastModified < aFile.DateLastModified Then Set fNewest = aFile End If End If Next MsgBox fNewest.Name -- Thanks & Best Regards |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
See http://www.cpearson.com/Excel/FileTimes.htm for downloadable code
that can get the create date, modify date, and access date for a file. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Thu, 6 May 2010 18:48:01 -0700, LeeL wrote: Can the function include way to get other attributes such as: Datecreated, DateLastModified, and DateLastAccessed? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to Use DateLastModified Property in VBA? | Excel Discussion (Misc queries) | |||
wildcard | Excel Programming | |||
Wildcard | Excel Programming | |||
DateLastModified | Excel Worksheet Functions | |||
DateLastModified property date extraction | Excel Programming |