
18-11-12, 21:28
|
 | Διαχειριστής Όνομα: Τάσος Φιλοξενιδης Έκδοση λογισμικού Office: Ms-Office 365 Γλώσσα λογισμικού Office: Ελληνική, Αγγλική, Γερμανική | | Εγγραφή: 21-10-2009
Μηνύματα: 2.035
| |
Καλησπέρα Πάνο και καλωσόρισες στο φόρουμ!
Η παρακάτω συνάρτηση (GetLastCreatedTextFile) επιστρέφει το πιο πρόσφατο αρχείο *.txt που υπάρχει στον υποφάκελο με
την πιο πρόσφατη ημερομηνία δημιουργίας και μπορεί να προσαρμοστεί πολύ εύκολα.: Κώδικας: Option Explicit
Sub Test()
Debug.Print GetLastCreatedTextFile("F:\Desktop\141012")
End Sub
Function GetLastCreatedTextFile(ParentParentFolderPath As String) As String
Dim fso As Object, oFolder As Object, dtDate As Date, strPath As String
Dim oSubFolder As Object, oFile As Object
On Error GoTo ExitHere
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(ParentParentFolderPath) Then
Set oFolder = fso.GetFolder(ParentParentFolderPath)
If oFolder.SubFolders.Count Then
dtDate = 1
For Each oSubFolder In oFolder.SubFolders
If oSubFolder.DateCreated > dtDate Then
dtDate = oSubFolder.DateCreated
strPath = oSubFolder.Path
End If
Next
Set oFolder = fso.GetFolder(strPath)
dtDate = 1
strPath = ""
For Each oFile In oFolder.Files
If UCase(fso.GetExtensionName(oFile.Name)) = "TXT" Then
If oFile.DateCreated > dtDate Then
dtDate = oFile.DateCreated
strPath = oFile.Path
End If
End If
Next
If strPath <> "" Then
GetLastCreatedTextFile = strPath
Else
GetLastCreatedTextFile = "No Textfiles found in folder '" & oFolder.Path & "'"
End If
Else
GetLastCreatedTextFile = "Could not find the any subfolders in folder '" & ParentParentFolderPath & "'"
End If
Else
GetLastCreatedTextFile = "Could not find the folder '" & ParentParentFolderPath & "'"
End If
ExitHere:
Set fso = Nothing
If Err <> 0 Then GetLastCreatedTextFile = Err.Description
End Function
Φιλικά
Τάσος
__________________ Ms-Office Development Team Ανάπτυξη επαγγελματικών εφαρμογών
Τελευταία επεξεργασία από το χρήστη Tasos : 18-11-12 στις 22:02.
|