Betrifft: Datei speichern unter +1 vomn Datei
von: Urmila
Hallo alle zusammen,
zunächst mal ein frohes neues Jahr an Allen....und hoffe euch Allen geht's gut.... :D
Brauche mal wieder eure Hilfe, und zwar:
In einem Ordner soll eine Datei abgespeichert werden, Speichername soll sein: 001-heutiges Datum (001-05.01.2010) die Nummer soll dann immer um 1 höher gesetzt werden, 001, 002, 003 usw. Datum immer aktuelles (ist ja eine DATE Anweisung) aber wie sage ich ihm dass er eine Zahl höher setzen soll von den vorhandenen Dateien...?
Hoffe es war verständlich und ihr könnt mir weiterhelfen...
Danke und LG
Urmila
Betrifft: AW: Datei speichern unter +1 vomn Datei
von: Josef Ehrensberger
Sub nn()
Dim strPath As String, strFile As String, strNewName As String
Dim lngMax As Long
strPath = "E:\Temp\" 'Pfad - Anpassen!
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFile = Dir(strPath & "###-##.##.####.xls*")
Do While strFile <> ""
lngMax = Application.Max(lngMax, Clng(Left(strFile, 3)))
strFile = Dir
Loop
strNewName = strPath & Format(lngMax + 1, "000-") & Format(Date, "dd.MM.yyyy") & ".xls"
End Sub
Betrifft: AW: Datei speichern unter +1 vomn Datei
von: Urmila
Dim strPath As String, strFile As String, strNewName As String
Dim lngMax As Long
strPath = "C:\New Folder\" 'Pfad - Anpassen!
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFile = Dir(strPath & "###-##.##.####.xls*")
Do While strFile <> ""
lngMax = Application.Max(lngMax, CLng(Left(strFile, 3)))
strFile = Dir
Loop
strNewName = strPath & Format(lngMax + 1, "000-") & Format(Date, "dd.MM.yyyy") & ".xls"
ActiveWorkbook.SaveAs Filename:=strNewName _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
danke und lg
Betrifft: AW: Datei speichern unter +1 vomn Datei
von: Josef Ehrensberger
Sub nn()
Dim strPath As String, strFile As String, strNewName As String
Dim lngMax As Long
strPath = "E:\Temp\" 'Pfad - Anpassen!
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFile = Dir(strPath & "???-??.??.????.xl*")
Do While strFile <> ""
If IsDate(Mid(strFile, 5, 10)) Then
If CDate(Mid(strFile, 5, 10)) = Date Then
lngMax = Application.Max(lngMax, Clng(Left(strFile, 3)))
End If
End If
strFile = Dir
Loop
strNewName = strPath & Format(lngMax + 1, "000-") & Format(Date, "dd.MM.yyyy") & ".xls"
ActiveWorkbook.SaveAs Filename:=strNewName
End Sub
Betrifft: suuuper....funktioniert :)
von: Urmila
Geschrieben am: 05.01.2010 14:43:43
LG
Urmila