I recently switched from excel 2003 to Open Office 4.1.3. With excel I was using a Macro with the following functionality:
- print an invoice twice
- save the invoice to a specific path with the file name "Rechnung.Cell from Invoice.Cell from invoice.xls"
- save the file as "Rechnung.xls"
So far, the macro is working fine and is printing and defining the file name correctly. The only issue I face is the "saveAs" function as this is not working properly. Could someone help me out here?
Note: path was generalized for data security also MsgBoxes are used for debugging, that's why I know the filenames and paths are defined correctly.
Code: Select all
Sub PrintInvoice()
'Sheet1.PrintOut
'Sheet1.PrintOut
On Error GoTo Fehler
Dim DName As String, Dateiname As String, Pfad As String
MsgBox "Variablen wurden deklariert "
Pfad = "D:\RECHNUNGEN\RECH.2017"
MsgBox "Pfad wurde gesetzt als: " & Pfad
DName = "Rech."
MsgBox "DName wurde gesetzt als: " & DName
Dateiname = Pfad & "\" & DName & Worksheets("Rechnung").Range("E9").Value & "." & Worksheets("Rechnung").Range("G2").Value & ".ods"
MsgBox "Dateiname wurde gesetzt als: " & Dateiname
ThisWorkbook.SaveAs Filename:=Dateiname
MsgBox "Datei erfolgreich gespeichert"
Fehler:
MsgBox "Datei wurde nicht gespeichert"
On Error GoTo Fehler2
Dim DName2 As String, Dateiname2 As String, Pfad2 As String
MsgBox "Variablen wurden deklariert "
Pfad2 = "C:\Benutzer\USERNAME\Desktop"
MsgBox "Pfad wurde gesetzt als: " & Pfad2
DName2 = "Rechnungen.xls"
MsgBox "DName2 wurde gesetzt als: " & DName2
Dateiname2 = Pfad2 & "\" & DName2
MsgBox "Dateiname wurde gesetzt als: " & Dateiname2
ThisWorkbook.SaveAs Filename:=Dateiname2
MsgBox "Datei erfolgreich gespeichert"
Exit Sub