Gruppe
Datei
Problem
Wie kann ich in einem vorgegebenen Verzeichnis die neueste Textdatei suchen und diese umbenennen?
StandardModule: basMain
Sub RenameTextFile()
Dim dat As Date
Dim iCounter As Integer
Dim sFile As String, sPath As String
sPath = Range("B1").Value
If Right(sPath, 1) <> "\" Then
sPath = sPath & "\"
End If
With Application.FileSearch
.LookIn = Left(sPath, Len(sPath) - 1)
.FileName = "*.txt"
.SearchSubFolders = False
.Execute
For iCounter = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(iCounter)) > dat Then
sFile = .FoundFiles(iCounter)
End If
Next iCounter
End With
If sFile <> "" Then
If Dir(sPath & "letzte.txt") <> "" Then
Kill sPath & "letzte.txt"
End If
Name sFile As sPath & "letzte.txt"
MsgBox "Die Datei" & vbLf & _
sFile & vbLf & " wurde umbenannt in " & vbLf & _
sPath & "letzte.txt"
Else
MsgBox "Es wurde keine Textdatei gefunden!"
End If
End Sub