Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1124to1128
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

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

Datei speichern unter +1 vomn Datei
05.01.2010 11:59:44
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

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

Betreff
Datum
Anwender
Anzeige
AW: Datei speichern unter +1 vomn Datei
05.01.2010 12:08:38
Josef Ehrensberger
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
Anzeige
AW: Datei speichern unter +1 vomn Datei
05.01.2010 13:19:49
Urmila
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
Anzeige
AW: Datei speichern unter +1 vomn Datei
05.01.2010 13:32:14
Josef Ehrensberger
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
Anzeige
suuuper....funktioniert :)
05.01.2010 14:43:43
Urmila
LG
Urmila

313 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige