Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1352to1356
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Ordner Datum ändern

Ordner Datum ändern
07.03.2014 15:05:11
Pepi
Hallo Zusammen
Ich habe einen Code gefunden, der das Erstelldatum einer Datei ändert. Das ist wunderbar. Leider funktioniert dieser Code nicht für Ordner (vieleicht braucht es eine Anpassung - ich verstehe den Code zuwenig!) Ich habe viele Ordner auf dem PC, die am TV in wilder Reihenfolge erscheinen, so will ich das Erstelldatum (Aenderungsdatum) ändern und jeweils um 1 Min. erhöhen, damit die Reihenfolge dem Orndernamen entspricht. (leider keine Sortiermöglichkeit beim TV)
hoffe auch einen Vorschlag
Pepi
Option Explicit
'04.03.14 von http://www.netz-treff.de/forum/archiveviewer.php?id=148299 rauskopiert (Erstelldatum, Aenderungsdatum, letzter Zugriff)
' zunächst die benötigten Deklarationen
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" ( _
ByVal hFile As Long, _
lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" ( _
ByVal hFile As Long, _
lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" ( _
lpFileTime As FILETIME, _
lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" ( _
lpFileTime As FILETIME, _
lpSystemTime As SYSTEMTIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" ( _
lpSystemTime As SYSTEMTIME, _
lpFileTime As FILETIME) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" ( _
lpLocalFileTime As FILETIME, _
lpFileTime As FILETIME) As Long
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
' Die beiden nachfolgenden Routinen werden zum
' Lesen/Schreiben der Zeitangaben benötigt
Private Function ReadFileTime(ByVal sFilename As String, _
tCreation As Date, tLastAccess As Date, _
tLastWrite As Date) As Boolean
' *** Datum/Zeitwert einer Datei ermitteln
Dim fHandle As Long
Dim ftCreation As FILETIME
Dim ftLastAccess As FILETIME
Dim ftLastWrite As FILETIME
Dim LocalFileTime As FILETIME
Dim LocalSystemTime As SYSTEMTIME
ReadFileTime = False
fHandle = CreateFile(sFilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)
If fHandle  0 Then
' Zeitinformationen auslesen
If GetFileTime(fHandle, ftCreation, ftLastAccess, ftLastWrite)  0 Then
' Erstellungsdatum
FileTimeToLocalFileTime ftCreation, LocalFileTime
FileTimeToSystemTime LocalFileTime, LocalSystemTime
With LocalSystemTime
tCreation = CDate(Format$(.wDay) & "." & _
Format$(.wMonth) & "." & Format$(.wYear) & " " & _
Format$(.wHour) & ":" & Format$(.wMinute, "00") & ":" & Format$(.wSecond, "00"))
End With
' Letzter Zugriff
FileTimeToLocalFileTime ftLastAccess, LocalFileTime
FileTimeToSystemTime LocalFileTime, LocalSystemTime
With LocalSystemTime
tLastAccess = CDate(Format$(.wDay) & "." & _
Format$(.wMonth) & "." & Format$(.wYear) & " " & _
Format$(.wHour) & ":" & Format$(.wMinute, "00") & ":" & Format$(.wSecond, "00"))
End With
' Letzte Änderung
FileTimeToLocalFileTime ftLastWrite, LocalFileTime
FileTimeToSystemTime LocalFileTime, LocalSystemTime
With LocalSystemTime
tLastWrite = CDate(Format$(.wDay) & "." & _
Format$(.wMonth) & "." & Format$(.wYear) & " " & _
Format$(.wHour) & ":" & Format$(.wMinute, "00") & ":" & Format$(.wSecond, "00"))
End With
ReadFileTime = True
End If
CloseHandle fHandle
End If
End Function

Private Function WriteFileTime(ByVal sFilename As String, _
ByVal tCreation As Date, ByVal tLastAccess As Date, ByVal tLastWrite As Date) As Boolean
' *** Datum/Zeitwert einer Datei setzen
Dim fHandle As Long
Dim ftCreation As FILETIME
Dim ftLastAccess As FILETIME
Dim ftLastWrite As FILETIME
Dim LocalFileTime As FILETIME
Dim LocalSystemTime As SYSTEMTIME
WriteFileTime = False
fHandle = CreateFile(sFilename, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If fHandle  0 Then
' Erstellungsdatum
With LocalSystemTime
.wDay = Day(tCreation)
.wDayOfWeek = Weekday(tCreation)
.wMonth = Month(tCreation)
.wYear = Year(tCreation)
.wHour = Hour(tCreation)
.wMinute = Minute(tCreation)
.wSecond = Second(tCreation)
End With
SystemTimeToFileTime LocalSystemTime, LocalFileTime
LocalFileTimeToFileTime LocalFileTime, ftCreation
' Letzter Zugriff
With LocalSystemTime
.wDay = Day(tLastAccess)
.wDayOfWeek = Weekday(tLastAccess)
.wMonth = Month(tLastAccess)
.wYear = Year(tLastAccess)
.wHour = Hour(tLastAccess)
.wMinute = Minute(tLastAccess)
.wSecond = Second(tLastAccess)
End With
SystemTimeToFileTime LocalSystemTime, LocalFileTime
LocalFileTimeToFileTime LocalFileTime, ftLastAccess
' Letzte Änderung
With LocalSystemTime
.wDay = Day(tLastWrite)
.wDayOfWeek = Weekday(tLastWrite)
.wMonth = Month(tLastWrite)
.wYear = Year(tLastWrite)
.wHour = Hour(tLastWrite)
.wMinute = Minute(tLastWrite)
.wSecond = Second(tLastWrite)
End With
SystemTimeToFileTime LocalSystemTime, LocalFileTime
LocalFileTimeToFileTime LocalFileTime, ftLastWrite
If SetFileTime(fHandle, ftCreation, ftLastAccess, ftLastWrite)  0 Then
WriteFileTime = True
End If
CloseHandle fHandle
End If
End Function
' #############################################################################################
Sub X_DateiDatumAendern()
Call SU_DateiDatumAendern(1, Range("K2"))
End Sub
Sub SU_DateiDatumAendern(iWah%, sCal$)
Dim k%, j%, Ja%, Mo%, Tg%, St%, Mi%, Se%, z%, iZeiAnz&, sTmp$, sDat$
Dim oTab As Object, oTC As Range, xA As Variant
xA = Split("0;31;28;31;30;31;30;31;31;30;31;30;31", ";")
Dim tCreation As Date 'Erstellt am
Dim tLastAccess As Date 'Letzter Zugriff
Dim tLastWrite As Date 'Letzte Änderung
Dim Datei As String
Const iPlu = 60 'Erhöhung um 5 Min.
On Error Resume Next
'ActiveWorkbook.BuiltinDocumentProperties(11) = Now - 1 '1= -24h, 11=Erstelldatum, 12=Aenderungsdatum
'ActiveWorkbook.BuiltinDocumentProperties(11) = Format(Now, "dd.mm.yy hh:mm:ss") - 1 '1= -24h, 11=Erstelldatum, 12=Aenderungsdatum
iZeiAnz = FU_Zeilen(2, 1)
If iZeiAnz Set oTab = Tab01
Set oTC = Tab01.Cells()
' ---------------------------------------------------------------------------------------------
ActiveWorkbook.Worksheets(oTab.Name).Sort.SortFields.Clear
If iWah = 1 Then
ActiveWorkbook.Worksheets(oTab.Name).Sort.SortFields.Add Key:=Range(oTC(2, 2), oTC(iZeiAnz, 2)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
Else
ActiveWorkbook.Worksheets(oTab.Name).Sort.SortFields.Add Key:=Range(oTC(2, 2), oTC(iZeiAnz, 2)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortTextAsNumbers
End If
With ActiveWorkbook.Worksheets(oTab.Name).Sort
.SetRange Range(oTC(1, 1), oTC(iZeiAnz, 2))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' ---------------------------------------------------------------------------------------------
If IsDate(sCal) Then
sDat = Format(CDate(sCal), "dd.mm.yyyy 06:00:00")
Else
sDat = Format(Now, "dd.mm.yyyy hh:00:00") ' Datum auslesen, Min. und Sek. auf Null
End If
Tg = Left(sDat, 2)
Mo = Mid(sDat, 4, 2)
Ja = Mid(sDat, 7, 4)
St = Mid(sDat, 12, 2)
Mi = Mid(sDat, 15, 2)
Se = Right(sDat, 2)
For z = 2 To iZeiAnz
Se = Se + iPlu 'Erhöhung pro Durchgang
Do While Se >= 60 'Schlaufe, damit Sekunden beliebig gross sein kann - 3600 entspricht 1 Std.
Se = Se - 60
Mi = Mi + 1
Loop
If Mi = 60 Then Mi = 0: St = St + 1
If St = 24 Then St = 0: Tg = Tg + 1
If Tg >= xA(Mo) Then Tg = 0: Mo = Mo + 1
If Mo = 13 Then Mo = 0: Ja = Ja + 1
k = k + 5
Cells(z, 11) = Format(Tg, "00.") & Format(Mo, "00.") & Format(Ja, "0000 ") & Format(St, "00:") & Format(Mi, "00:") & Format(Se, "00") 'Format(Now + TimeValue("0:00:" & k))
' ---------------------------------------------------------------------------------------------
'Zeitangaben lesen
If ReadFileTime(oTC(z, 2), tCreation, tLastAccess, tLastWrite) Then
'Erstellungsdatum ändern
tCreation = CDate(oTC(z, 11))
'Datum "Letzter Zugriff" ändern
tLastAccess = CDate(oTC(z, 11)) 'CDate("01.11.2013 17:36:00")
'Datum "Letzter Änderung" ändern
tLastWrite = CDate(oTC(z, 11)) 'CDate("01.11.2013 17:37:00")
'Zeitangaben setzen
WriteFileTime oTC(z, 2), tCreation, tLastAccess, tLastWrite
End If
Next z
End Sub

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Ordner Datum ändern
07.03.2014 18:39:10
Oberschlumpf
Hi ?
VBA = gut?
Dann solltest doch auch du wissen, dass Code, nur in deinem Beitrag gezeigt, ohne Excel nicht wirklich funktioniert.
Warum zeigst du uns nicht eine Bsp-Datei, die den Code enthält?
Ciao
Thorsten

AW: Ordner Datum ändern
08.03.2014 10:00:40
Pepi
Hallo Thorsten
Wie recht du doch hast - auch mit "gut" ist so eine Sache - "ich weiss, dass ich nichts weiss"
https://www.herber.de/bbs/user/89588.xlsm
Vielleicht lässt sich der Code leicht anpassen - wäre toll
vielen Dank
Pepi

AW: Ordner Datum ändern
08.03.2014 10:31:09
Oberschlumpf
Hi
Danke für die Bsp-Datei.
Ich musste sie trotzdem neu erstellen, da ich noch Excel 2003 benutze.
Deine Datei konnte ich zwar öffnen, aber mit Fehler, und der Code wurde nicht ausgeführt.
Versuch es mal hiermit:
https://www.herber.de/bbs/user/89589.xls
Du musst im Code in der S u b sbStart den Wert für sFolder anpassen.
Der Code ändert das Datum für einen Ordner, der halt in sbStart angegeben werden muss.
Du musst halt den Code noch anpassen, da du ja das Erstelldatum für viele Ordner ändern willst.
Hilfts denn?
Ciao
Thorsten
den Code fand ich hier:
http://www.vbarchiv.net/tipps/tipp_593-datum-und-uhrzeit-eines-ordners-ndern.html

Anzeige
AW: Ordner Datum ändern
08.03.2014 10:58:37
Pepi
Hallo Thorsten
Ich werde den Code noch genau vergleichen, damit ich mit dem gleichen Makro Ordner und Datei ändern kann.
Doch mindestens funktioniert er genau so, wie ich mir das wünschte.
vielen Dank
Pepi

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige