Forumbeitrag
Excel-Version des Fragestellers:
2022
Erfahrungslevel des Fragestellers:
VBA nur mit Recorder
2
Oberschlumpf
Hi,
Danke bei mir hat bereits zuvor alles funktioniert. :-)
Soferne ich Pfade kopiere werden bei mir in Total Commander 11.03 oder Everything 1.5.0.1383a (x64)
die Pfade IMMER mit einem abschließenden Backslash kopiert (ohne Anführungszeichen),
d.h. der vorherige Code würde bei mir IMMER funktionieren, und zwar
auch MIT Leerzeichen im Pfad und OHNE Anführungszeichen im Eingabefeld.
Jetzt habe ich den
CODE noch auf Deinen Vorschlag hin geändert und er
funktioniert ebenfalls PERFEKT!
Mein finaler Code lautet:
Sub Save_ACTIVE_SHEET_to_specified_PATH()
' https://www.herber.de/forum/messages/1984803.html - Topic "Makro (bitte prüfen) - Aktives Blatt auf Desktop speichern"
' https://www.herber.de/forum/messages/1984845.html - Next post - Solution from 15 July 2024
' -----------------------------------------------------------------------------------------------------------------------------
' English:
' 1. If the input field is left EMPTY after the macro is called, the Excel file is saved in the PATH,
' which was defined in the MACRO. EXAMPLE - 2nd line of the code ...: lstrStdPfad = "C:\Everything\Tests\"
' It is NOT necessary to enter the file extension, e.g. .xlsm!
'
' 2. If the input field is FILLED with a PATH after the macro is called - followed by a BACKSLASH '\',
' then the Excel file is saved in this path. It is NOT necessary to enter the file extension, e.g. .xlsm!
' It is also NOT necessary to put a path with spaces in inverted commas.
' -----------------------------------------------------------------------------------------------------------------------------
' German:
' 1. Wird nach Aufruf des Makros das Eingabefeld LEER gelassen, dann wird die Excel-Datei in jenem PFAD gespeichert,
' welcher im MAKRO definiert wurde. BEISPIEL - 2. Zeile im Code ...: lstrStdPfad = "C:\Everything\Tests\"
' Die Angabe der Dateierweiterung, zB .xlsm ist NICHT erforderlich!
'
' 2. Wird nach Aufruf des Makros das Eingabefeld mit einem PFAD - abschließend mit einem BACKSLASH '\' BEFÜLLT,
' dann wird die Excel-Datei in diesem Pfad gespeichert. Die Erfassung der Dateierweiterung, zB .xlsm ist NICHT erforderlich!
' Es ist auch NICHT erforderlich einen Pfad mit Leerzeichen in Anführungszeichen zu setzen.
' -----------------------------------------------------------------------------------------------------------------------------
Dim lstrStdPfad As String
lstrStdPfad = "C:\Everything\Tests\"
Path = InputBox("Enter the path in which the sheet is to be saved - the file name extension (.xl??) is automatically added according to the file format!")
If Mid(Path, 2, 1) <> ":" Then
Path = lstrStdPfad
End If
Select Case Right(Path, 1)
Case ""
GoTo ErrorHandler
Case Is <> "\"
Path = Path & "\"
End Select
ActiveSheet.Copy
On Error GoTo ErrorHandler
' ActiveWorkbook.SaveAs Filename:=path & ActiveSheet.Name => Excel 2003
' ActiveWorkbook.SaveAs Filename:=path & ActiveSheet.Name, FileFormat:=52 => Excel 2010: The file name extension can be omitted,
' https://www.herber.de/forum/archiv/1380to1384/1380461_Excel_2010_per_makro_tabellenblatt_in_neue_Datei.html => Excel adds them automatically according to the file format.
ActiveWorkbook.SaveAs Filename:=Path & ActiveSheet.Name, FileFormat:=52
ActiveWorkbook.Close Savechanges:=False
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 1004
MsgBox ("Saving was NOT successful! - Check the path...")
ActiveWorkbook.Close Savechanges:=False
Case Else
End Select
End Sub
Besten Dank für Deine Bemühungen!
Gruß,
Karl
PS:
Ich werde versuchen anderen Helfern noch zu antworten.
Konnte noch nicht alle Vorschläge prüfen, zB "Speichern auf Desktop" von User
daniel.
An jene Profi-Unterstützer die hier mitlesen:
Vielen herzlichen Dank für die vielen Vorschläge und die Unterstützung!