AW: Dateiname und Änderungsdatum auslesen
07.02.2023 13:14:55
ChrisL
Hi David
ChatGPT (Link im Titel) hat die Arbeit erledigt:
Excel VBA erstelle eine Excel Tabelle mit allen Dateien von einem bestimmten Ordner und dem letzten Änderungsdatum
Sie können die Dateien in einem bestimmten Ordner mithilfe von VBA und den Funktionen von Windows einlesen. Hier ist ein Beispielcode, um alle Dateien in einem bestimmten Ordner und das jeweilige Datum ihrer letzten Änderung in einer Excel-Tabelle aufzulisten:
Sub ListFilesInFolder()
Dim MyPath As String, MyFile As String, MySheet As Worksheet
Dim R As Long
'Define the path to the folder
MyPath = "C:\MyFolder"
'Set the worksheet you want to write the file list to
Set MySheet = ThisWorkbook.Sheets("Sheet1")
'Clear the worksheet
MySheet.Cells.Clear
'Add headers for the file name and last modified date
MySheet.Cells(1, 1).Value = "File Name"
MySheet.Cells(1, 2).Value = "Last Modified"
'Start at the second row of the worksheet
R = 2
'Get a list of all the files in the folder
MyFile = Dir(MyPath & "\*.*")
Do While MyFile > ""
'Write the file name and last modified date to the worksheet
MySheet.Cells(R, 1).Value = MyFile
MySheet.Cells(R, 2).Value = FileDateTime(MyPath & "\" & MyFile)
'Move to the next row in the worksheet
R = R + 1
'Get the next file in the folder
MyFile = Dir
Loop
End Sub
Stellen Sie sicher, dass Sie den Pfad in Zeile 9 an Ihre Bedürfnisse anpassen. Führen Sie dann den Code aus, indem Sie ihn in der Visual Basic-Umgebung ausführen oder indem Sie die Tastenkombination ALT + F8 drücken.
cu
Chris