LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Finding files using Dir

How about this:

Private Sub CommandButton1_Click()
Debug.Print GetOldestModifiedFile("C:")
End Sub

Public Function GetOldestModifiedFile(argFolderToSearch As String, _
Optional argPattern As String =
"*.xls") _
As String
Dim FileName As String
Dim FileDate As Date
Dim OldestDate As Date
Dim OldestFile As String

If Right(argFolderToSearch, 1) < "\" Then argFolderToSearch =
argFolderToSearch & "\"
OldestFile = ""
OldestDate = 50000

FileName = Dir(argFolderToSearch & argPattern, vbNormal)
Do Until FileName = ""
FileDate = FileDateTime(argFolderToSearch & FileName)
If FileDate < OldestDate Then
OldestDate = FileDate
OldestFile = FileName
End If
FileName = Dir()
Loop
GetOldestModifiedFile = OldestFile

End Function

NickHK

"farful" wrote in
message ...

Hi, I was wondering if someone could show me how, give a directory (no
need for sub directories or hidden files or system files, etc) to open
the last modified excel file given a partial string (the beginning part
of the filename) using VBA, preferably using the "Dir" function.


--
farful
------------------------------------------------------------------------
farful's Profile:

http://www.excelforum.com/member.php...o&userid=36172
View this thread: http://www.excelforum.com/showthread...hreadid=563360



 
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
Finding a word in CSV files DennisT Excel Discussion (Misc queries) 4 December 1st 08 04:04 PM
finding excel files Novice in B-ton New Users to Excel 2 October 14th 08 07:42 PM
Finding Excel files Tommy H Excel Discussion (Misc queries) 0 August 29th 06 02:53 PM
Finding files in a directory farful[_6_] Excel Programming 3 July 19th 06 09:41 PM
filesearch not finding files Kevin Excel Programming 1 January 18th 05 01:49 PM


All times are GMT +1. The time now is 12:30 PM.

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"