Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Locate Most Recent File


Hi All,

I need to be able to locate the most recent file within a specifie
directory so that I can use it for other parts of my code.

Does anyone have any clever ideas on how you can do this?

Thanks

Andy

;

--
andibeva
-----------------------------------------------------------------------
andibevan's Profile: http://www.excelforum.com/member.php...nfo&userid=988
View this thread: http://www.excelforum.com/showthread.php?threadid=27274

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Locate Most Recent File

Try this piece of code:

Sub Most_Recent_File()
Dim fs, f, f1
Dim vDT As Date
Dim vFName As String
fldr = "C:\Documents\Spreadsheets\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder(fldr)
Set f1 = f.Files
For Each f2 In f1
If f2.DateLastModified vDT Then
vFName = f2.Name
vDT = f2.DateLastModified
End If
Next
Debug.Print vFName, vDT
End Sub

HTH,
Nikos

"andibevan" wrote in message
...

Hi All,

I need to be able to locate the most recent file within a specified
directory so that I can use it for other parts of my code.

Does anyone have any clever ideas on how you can do this?

Thanks

Andy

;)


--
andibevan
------------------------------------------------------------------------
andibevan's Profile:

http://www.excelforum.com/member.php...fo&userid=9882
View this thread: http://www.excelforum.com/showthread...hreadid=272742



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Locate Most Recent File

maybe not clever but it works..

Sub mrf()
Dim szFile(1) As String
Dim dtFile(1) As Date

szFile(0) = Dir("*.xls")

While Not szFile(0) = vbNullString
dtFile(0) = VBA.FileDateTime(szFile(0))
If dtFile(0) dtFile(1) Then
dtFile(1) = dtFile(0)
szFile(1) = szFile(0)
End If
szFile(0) = Dir()
Wend

MsgBox szFile(1) & " timestamp " & dtFile(1)

End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


andibevan wrote:


Hi All,

I need to be able to locate the most recent file within a specified
directory so that I can use it for other parts of my code.

Does anyone have any clever ideas on how you can do this?

Thanks

Andy

;)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Locate Most Recent File

The filesearch object should be able to help you. Look in Excel VBA help
for details and sample code.

--
Regards,
Tom Ogilvy

"andibevan" wrote in message
...

Hi All,

I need to be able to locate the most recent file within a specified
directory so that I can use it for other parts of my code.

Does anyone have any clever ideas on how you can do this?

Thanks

Andy

;)


--
andibevan
------------------------------------------------------------------------
andibevan's Profile:

http://www.excelforum.com/member.php...fo&userid=9882
View this thread: http://www.excelforum.com/showthread...hreadid=272742



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 do I locate a file containing 'great lakes'? Eugeseals Excel Discussion (Misc queries) 2 March 5th 10 01:56 PM
how do i delete a file from recent documents file in excel exile New Users to Excel 1 March 7th 09 01:59 AM
How do I locate the excel sort file? Network Excel Discussion (Misc queries) 2 March 2nd 06 06:18 PM
Most Recent File problem - Help!! Wibs Excel Discussion (Misc queries) 1 November 20th 05 01:21 PM
~Recent File~ andibevan Excel Worksheet Functions 2 November 19th 04 08:52 PM


All times are GMT +1. The time now is 10:30 AM.

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

About Us

"It's about Microsoft Excel"