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

Creating a macro - Writing a Script - Using the API

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

Postby feedy » Sun Sep 10, 2017 7:36 pm

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   Expand viewCollapse view
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
feedy
 
Posts: 2
Joined: Sun Sep 10, 2017 7:11 pm

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

Postby Zizi64 » Sun Sep 10, 2017 7:41 pm

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.1 and AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7768
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby feedy » Sun Sep 10, 2017 8:34 pm

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
feedy
 
Posts: 2
Joined: Sun Sep 10, 2017 7:11 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests