> Private Shared Function GetLatestExcelFileInDir(ByVal dir As String) As String > > Dim dirInfo As System.IO.DirectoryInfo > Dim files As System.IO.FileInfo() > Dim datesAndNames As String() > Dim dt As DateTime > > Try > 'Get directory info of dir > dirInfo = New System.IO.DirectoryInfo(dir) > 'Get excel files in dir > files = dirInfo.GetFiles("*.xls") > 'Create string array to hold file names and dates > datesAndNames = New String(files.Length - 1) {} > > 'Enumerate through files > For i As Integer = 0 To files.Length - 1 > 'Get creation date of file > dt = files(i).CreationTime > 'Store creation date and file name in one text field > datesAndNames(i) = dt.ToString("yyyy/MM/dd HH:mm ") & files(i).FullName > Next > > 'Sort the array (ends up sorting by date) > Array.Sort(datesAndNames) > > 'Return file name with date trimmed off > Return datesAndNames(files.Length - 1).Substring(17) > > Catch ex As Exception > Throw (New Exception) > End Try > End Function >