Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default Using FileSystemObject to get File

This is probably not so much an Excel Programming question, but I'm
hoping someone can help me here.

I have a script that sends an Excel file by email each day. It has to
choose the most recent file from a given folder. The file names are
like this:

MyFile Jan 01.xls
MyFile Jan 02.xls
MyFile Jan 03.xls
etc..........

Is there a way to use FileSystemObject to get the file with the latest
date? I can't use the Format function in script, or otherwise this
would be easier.

tod
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using FileSystemObject to get File



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"tod" wrote in message
om...
This is probably not so much an Excel Programming question, but I'm
hoping someone can help me here.

I have a script that sends an Excel file by email each day. It has to
choose the most recent file from a given folder. The file names are
like this:

MyFile Jan 01.xls
MyFile Jan 02.xls
MyFile Jan 03.xls
etc..........

Is there a way to use FileSystemObject to get the file with the latest
date? I can't use the Format function in script, or otherwise this
would be easier.

tod



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using FileSystemObject to get File

Tod,

Here's a solution using FileSearch

Function GetLatestFile(Folderr As String) As String
Dim LastFile
Dim LastFileDateTime
Dim i As Long

LastFileDateTime = 0

With Application.FileSearch
.NewSearch
.LookIn = Folder
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = False
.Execute
For i = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(i)) LastFileDateTime Then
LastFileDateTime = FileDateTime(.FoundFiles(i))
LastFile = .FoundFiles(i)
End If
Next i
End With

GetLatestFile = Replace(LastFile, "~$", "")

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"tod" wrote in message
om...
This is probably not so much an Excel Programming question, but I'm
hoping someone can help me here.

I have a script that sends an Excel file by email each day. It has to
choose the most recent file from a given folder. The file names are
like this:

MyFile Jan 01.xls
MyFile Jan 02.xls
MyFile Jan 03.xls
etc..........

Is there a way to use FileSystemObject to get the file with the latest
date? I can't use the Format function in script, or otherwise this
would be easier.

tod



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
Scripting.FileSystemObject Leif Rasmussen Excel Discussion (Misc queries) 1 January 12th 05 11:21 PM
Scripting.FileSystemObject LAN Mirom Excel Programming 0 January 3rd 04 06:30 AM
Creating FileSystemObject Kirk[_2_] Excel Programming 2 September 9th 03 10:24 PM
Help with FileSystemObject? Ed[_9_] Excel Programming 2 August 5th 03 12:08 AM
FileSystemObject to get last 10 lines of text file. john Excel Programming 11 July 16th 03 03:54 PM


All times are GMT +1. The time now is 10:55 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"