PC Review


Reply
Thread Tools Rate Thread

2 Most recent files

 
 
Richard
Guest
Posts: n/a
 
      3rd Jun 2008
Hi,

I need to open the 2 most recent files in a spcific folder. The files will
have the same name, but will also have the date "yy_mm_dd" as part of the
file name. The file with todays date will obviously be the most recent,
however there is no guarantee that the next most recent has the previous
working days date.

How do I open the 2nd most recent file?

Thanks
Richard
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      3rd Jun 2008
This lists the two file names. You can use those names to open the files.
Note that an open file will have the current date.
'--
Sub TheTwoLatestFiles()
'Jim Cone - San Francisco, USA - June 2005
'Jim Cone - Portland Oregon - June 2008. Modified to show additional file.
'Displays the two latest file names in the strPath folder.

Dim objFSO As Object
Dim objFile As Object
Dim objFolder As Object
Dim strPath As String
Dim strName_1 As String
Dim strName_2 As String
Dim dteCreated_1 As Date
Dim dteCreated_2 As Date

' Specify the folder...
strPath = "C:\Program Files\Microsoft Office\Office11\Library"

' Use Microsoft Scripting runtime.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)

' Check date on each file in folder.
For Each objFile In objFolder.Files
If objFile.DateLastModified > dteCreated_1 Then
dteCreated_1 = objFile.DateLastModified
strName_1 = objFile.Name
ElseIf objFile.DateLastModified > dteCreated_2 Then
dteCreated_2 = objFile.DateLastModified
strName_2 = objFile.Name
End If
Next 'objFile

' Display file names in message box.
MsgBox strName_1 & " " & Format(dteCreated_1, "Short Date") & vbCr _
& strName_2 & " " & Format$(dteCreated_2, "short Date") _
& vbCr & "are the two latest files ", , "Blame Jim Cone"

Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Richard" <(E-Mail Removed)>
wrote in message
Hi,
I need to open the 2 most recent files in a spcific folder. The files will
have the same name, but will also have the date "yy_mm_dd" as part of the
file name. The file with todays date will obviously be the most recent,
however there is no guarantee that the next most recent has the previous
working days date.
How do I open the 2nd most recent file?
Thanks
Richard
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      4th Jun 2008
Jim

That is great thanks for your help

Cheers
Richard

"Jim Cone" wrote:

> This lists the two file names. You can use those names to open the files.
> Note that an open file will have the current date.
> '--
> Sub TheTwoLatestFiles()
> 'Jim Cone - San Francisco, USA - June 2005
> 'Jim Cone - Portland Oregon - June 2008. Modified to show additional file.
> 'Displays the two latest file names in the strPath folder.
>
> Dim objFSO As Object
> Dim objFile As Object
> Dim objFolder As Object
> Dim strPath As String
> Dim strName_1 As String
> Dim strName_2 As String
> Dim dteCreated_1 As Date
> Dim dteCreated_2 As Date
>
> ' Specify the folder...
> strPath = "C:\Program Files\Microsoft Office\Office11\Library"
>
> ' Use Microsoft Scripting runtime.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(strPath)
>
> ' Check date on each file in folder.
> For Each objFile In objFolder.Files
> If objFile.DateLastModified > dteCreated_1 Then
> dteCreated_1 = objFile.DateLastModified
> strName_1 = objFile.Name
> ElseIf objFile.DateLastModified > dteCreated_2 Then
> dteCreated_2 = objFile.DateLastModified
> strName_2 = objFile.Name
> End If
> Next 'objFile
>
> ' Display file names in message box.
> MsgBox strName_1 & " " & Format(dteCreated_1, "Short Date") & vbCr _
> & strName_2 & " " & Format$(dteCreated_2, "short Date") _
> & vbCr & "are the two latest files ", , "Blame Jim Cone"
>
> Set objFSO = Nothing
> Set objFolder = Nothing
> Set objFile = Nothing
> End Sub
> --
> Jim Cone
> Portland, Oregon USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
>
>
>
> "Richard" <(E-Mail Removed)>
> wrote in message
> Hi,
> I need to open the 2 most recent files in a spcific folder. The files will
> have the same name, but will also have the date "yy_mm_dd" as part of the
> file name. The file with todays date will obviously be the most recent,
> however there is no guarantee that the next most recent has the previous
> working days date.
> How do I open the 2nd most recent file?
> Thanks
> Richard
>

 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      9th Jun 2008
Jim

There seems to be some issue with this not picking up one of the files. Is
there a way of comparing the file names, which contain the date
received/created, rather than using the system modified date?

Thanks
Richard

"Jim Cone" wrote:

> This lists the two file names. You can use those names to open the files.
> Note that an open file will have the current date.
> '--
> Sub TheTwoLatestFiles()
> 'Jim Cone - San Francisco, USA - June 2005
> 'Jim Cone - Portland Oregon - June 2008. Modified to show additional file.
> 'Displays the two latest file names in the strPath folder.
>
> Dim objFSO As Object
> Dim objFile As Object
> Dim objFolder As Object
> Dim strPath As String
> Dim strName_1 As String
> Dim strName_2 As String
> Dim dteCreated_1 As Date
> Dim dteCreated_2 As Date
>
> ' Specify the folder...
> strPath = "C:\Program Files\Microsoft Office\Office11\Library"
>
> ' Use Microsoft Scripting runtime.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(strPath)
>
> ' Check date on each file in folder.
> For Each objFile In objFolder.Files
> If objFile.DateLastModified > dteCreated_1 Then
> dteCreated_1 = objFile.DateLastModified
> strName_1 = objFile.Name
> ElseIf objFile.DateLastModified > dteCreated_2 Then
> dteCreated_2 = objFile.DateLastModified
> strName_2 = objFile.Name
> End If
> Next 'objFile
>
> ' Display file names in message box.
> MsgBox strName_1 & " " & Format(dteCreated_1, "Short Date") & vbCr _
> & strName_2 & " " & Format$(dteCreated_2, "short Date") _
> & vbCr & "are the two latest files ", , "Blame Jim Cone"
>
> Set objFSO = Nothing
> Set objFolder = Nothing
> Set objFile = Nothing
> End Sub
> --
> Jim Cone
> Portland, Oregon USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
>
>
>
> "Richard" <(E-Mail Removed)>
> wrote in message
> Hi,
> I need to open the 2 most recent files in a spcific folder. The files will
> have the same name, but will also have the date "yy_mm_dd" as part of the
> file name. The file with todays date will obviously be the most recent,
> however there is no guarantee that the next most recent has the previous
> working days date.
> How do I open the 2nd most recent file?
> Thanks
> Richard
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
show most recent files first when opening excel files Anne` Microsoft Excel Misc 5 23rd Jan 2008 01:54 AM
FrontPage 2003 - Recent Files & Recent Sites List =?Utf-8?B?Qm9iIFo=?= Microsoft Frontpage 2 23rd Nov 2006 04:08 AM
offline files synch target files from ms office recent shortcut =?Utf-8?B?S29yeQ==?= Windows XP General 1 1st May 2006 01:57 PM
Recent Sites and Recent Files - Remove? Microsoft Frontpage 2 22nd Jul 2004 03:25 PM
Recent Files & Recent Sites Grayed Out in FP2003 =?Utf-8?B?Uk0=?= Microsoft Frontpage 3 22nd Apr 2004 09:57 AM


Features
 

Advertising
 

Newsgroups
 


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