[Solved] Imported macro from Excel 2003: Save As not working

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
feedy
Posts: 2
Joined: Sun Sep 10, 2017 7:11 pm

[Solved] Imported macro from Excel 2003: Save As not working

Post by feedy »

Hi Forum,

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
I am pretty sure this is also not the most efficient way to do it but it worked for me so far. I just really would need the save function in OOC. Thanks in advance!
Last edited by feedy on Mon Sep 11, 2017 12:34 am, edited 1 time in total.
Open Office 4.1.3
Windows 10 64 bit
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Calc] Imported macro from Excel 2003 - Save As not work

Post by Zizi64 »

The MS VBA and the StarBasic+API functions of the AOO/LO are not compatible.
You must rewrite all of the macros based on the API functions, if you want efficiently with AOO/LO.

The LibreOffice has a littlebit higher compatibility with the VBA - than the AOO has, but that compatibility value does not even approach the 100% value.
Last edited by Zizi64 on Sun Sep 10, 2017 8:50 pm, edited 2 times in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
feedy
Posts: 2
Joined: Sun Sep 10, 2017 7:11 pm

Re: [Calc] Imported macro from Excel 2003 - Save As not work

Post by feedy »

Thanks for the information. I have tried it with LibreOffice and it works perfectly fine! Thread can be closed :)
Open Office 4.1.3
Windows 10 64 bit
Post Reply