Results 1 to 4 of 4

Thread: Get the last updated file name.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    You could also write Admin's function using VB's built in FileDateTime function instead of calling out to the FileSystemObject scripting object (note that I reorganized the code in keeping with my own personal programming preferences)...

    Code:
    Function GetLastModifiedFile(ByVal FolderName As String, Optional FileType As String = "Excel") As String
      Dim FN As String, FileName As String, FileNamePattern As String
      Dim NewestFileName As String, MaxDate As Date
      If Right$(FolderName,1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator
      Select Case UCase(FileType)
        Case "EXCEL":      FileNamePattern = "*.xl*"
        Case "WORD":       FileNamePattern = "*.do*"
        Case "POWERPOINT": FileNamePattern = "*.pp*"
      End Select
      FN = Dir$(FolderName & FileNamePattern)
      Do While FN <> ""
        If FileDateTime(FolderName & FN) > MaxDate Then
          MaxDate = FileDateTime(FolderName & FN)
          NewestFileName = FN
        End If
        FN = Dir$
      Loop
      GetLastModifiedFile = NewestFileName
    End Function
    Last edited by Rick Rothstein; 04-11-2012 at 10:23 AM.

Similar Threads

  1. Replies: 19
    Last Post: 02-11-2013, 10:49 PM
  2. Import text file to an Excel file
    By obed_cruz in forum Excel Help
    Replies: 5
    Last Post: 08-03-2011, 07:58 PM
  3. Replies: 1
    Last Post: 06-02-2011, 10:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •