Private Function NewestFileInFolder(strFolderPath As String) As Integer
Dim objFSO As FileSystemObject, objFolder As Object, objFile As File, intTemp As Integer, bolFirstPass As Boolean
Set objFSO = CreateObject("Scripting.FileSystemobject")
Set objFolder = objFSO.GetFolder(strFolderPath)
bolFirstPass = True
For Each objFile In objFolder.Files
intTemp = DateDiff("d", objFile.DateCreated, Date)
If bolFirstPass Then
NewestFileInFolder = intTemp
bolFirstPass = False
Else
If intTemp < NewestFileInFolder Then NewestFileInFolder = intTemp
End If
Next
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
End Function
|