Herbers Excel-Forum - das Archiv

Datei speichern unter +1 vomn Datei | Herbers Excel-Forum


Betrifft: Datei speichern unter +1 vomn Datei
von: Urmila

Geschrieben am: 05.01.2010 11:59:44

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

Geschrieben am: 05.01.2010 12:08:38
Hallo Urmila,
vom Prinzip her, geht das z.B. so.
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

Gruß Sepp

Betrifft: AW: Datei speichern unter +1 vomn Datei
von: Urmila

Geschrieben am: 05.01.2010 13:19:49
Hallo Sepp,
habe den Code eingefügt und versucht, tut sich aber nichts.....
Habe ebenfalls in einem Modul eingefügt und die "ActiveWorkbook.SaveAs" Methode verwendet und da den Wert strNewName eingegeben, da fragt er dann ob er die Datei ersetzen soll, weil die Datei schon vorhanden ist... was mach ich da falsch?
  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
Urmila

Betrifft: AW: Datei speichern unter +1 vomn Datei
von: Josef Ehrensberger

Geschrieben am: 05.01.2010 13:32:14
Hallo Urmila,
ich sagte ja "vom Prinzip her".
Probier mal so.
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

Gruß Sepp

Betrifft: suuuper....funktioniert :)
von: Urmila
Geschrieben am: 05.01.2010 14:43:43
LG
Urmila

Excel-Beispiele zum Thema "Datei speichern unter +1 vomn Datei"
Zelleingaben speichern Die "personl"-Arbeitsmappe ausgeblendet speichern
Formeln mit Zelladressen speichern Bestätigung beim Speichern unterdrücken.
Arbeitsmappe unter dem Text eines Zelleintrags speichern Einzelnes Tabellenblatt speichern
Mappe unter Zelldatum speichern Arbeitsmappe doppelt speichern
Arbeitsmappe unter Namen speichern Programmabbruch bei Überspeichernabfrage verhindern
Bewerten Sie hier bitte das Excel-Portal