title: How to modify the VBA code that finds Oldest File date in a folder to find Newest File date in a folder?
body: <p>The below code helps in finding the oldest file date in a folder, but I am looking for a VBA code that can be help me in finding the newest file date or most recent file date in a folder.</p>
  
  <pre><code>    Sub oldestdate()
  
  Range("G10").Value = GetOldestFile("C:\Users\xxx\Downloads\My files")
  
  End Sub
  
  
  Public Function GetOldestFile(ByVal FileFolder As String, _
                                Optional ByVal FileMask As String = "*.*", _
                                Optional ByVal FullName As Boolean = True) As String
  
     Dim FoundFile        As String
     Dim FileDT           As Date
  
     Dim NewestFile       As String
     Dim NewestDT         As Date
  
     Dim FS As Object
  
     '// Get rid of any terminating '\' just to get to a known state
     If Right(Trim(FileFolder), 1) = "\" Then
        FileFolder = Left(FileFolder, Len(Trim(FileFolder)) - 1)
     End If
  
     '// Get First file found in described folder
     FoundFile = Dir$(FileFolder &amp; "\" &amp; FileMask)
  
     '// Default return date
     NewestDT = DateValue("1900-01-01")
  
     Set FS = CreateObject("Scripting.FileSystemObject")
  
     '// Loop through the rest of the files in that folder
     Do Until FoundFile = ""
  
        FileDT = FS.GetFile(FileFolder &amp; "\" &amp; FoundFile).DateCreated
  
        '// Compare Current File datetime with oldest found
        If FileDT &gt; NewestDT Then
           NewestFile = FoundFile
           NewestDT = FileDT
        End If
  
        '// Get next file
        FoundFile = Dir$
     Loop
  
     Set FS = Nothing
  
     GetOldestFile = Format(NewestDT, "mm/dd/yyyy")
  
  End Function
  </code></pre>
  
  <blockquote>
    <p>Please let me know how to find the newest file date in a folder.</p>
  </blockquote>