Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default how to get DateLastModified name with wildcard

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default how to get DateLastModified name with wildcard

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default how to get DateLastModified name with wildcard

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default how to get DateLastModified name with wildcard

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default how to get DateLastModified name with wildcard

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Use DateLastModified Property in VBA? HROBERTSON Excel Discussion (Misc queries) 3 May 6th 23 03:45 AM
wildcard JOUIOUI Excel Programming 5 July 31st 06 01:47 PM
Wildcard fugfug[_10_] Excel Programming 0 July 14th 05 12:34 PM
DateLastModified nina Excel Worksheet Functions 2 March 21st 05 02:11 PM
DateLastModified property date extraction Nigel[_6_] Excel Programming 6 November 15th 03 06:21 PM


All times are GMT +1. The time now is 03:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"