View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Macro to open most current file in folder


Sub LatestFileIs()
'Jim Cone - San Francisco, USA - June 2005
'Displays the latest file name in the strPath folder.

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim strPath As String
Dim strName As String
Dim dteDate As Date

' Specify the folder...
strPath = "C:\Program Files\Microsoft Office\Office\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 dteDate Then
dteDate = objFile.DateLastModified
strName = objFile.Name
End If
Next 'objFile

' Display file name in message box.
MsgBox strName & " - is latest file - " & dteDate

Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"Tasha"
wrote in message
Is there a way for a Macro to open the most current file in a folder? I have
a file copied to a specified folder nightly (C:\DLY\PB061807.txt) for
example. The PB stays the same in every file, and then it adds the date to
the end. There may be several in the folder(for example over the weekend, on
Monday there will be three files), but I am setting up a macro to run each
night and process the text file, but I need to find out how to get it to open
the most current file. Help???