[Solved] Calc: Macro for 'Save a Copy'
[Solved] Calc: Macro for 'Save a Copy'
I am trying to write a macro to run the 'Save a Copy' command and save a copy of the active sheet as a csv file in the same directory as the workbook. I searched and found many examples on this forum but they were all for Save As, and not Save a Copy. I couldn't find a reference in the Programmer's Guide either. Hoping someone here can help me with that.
Last edited by muaz12 on Sat Mar 10, 2018 12:55 am, edited 1 time in total.
LibreOffice Version: 5.1.6.2 on Ubuntu 16.04
Re: Calc: Macro for 'Save a Copy'
You must study the API functions included the functions StoreAsURL() and the StoreToURL(). (...and the usage of the export filters)
https://wiki.openoffice.org/wiki/Saving_a_document
https://wiki.openoffice.org/wiki/API/Tu ... PDF_export
viewtopic.php?f=9&t=2551
https://wiki.openoffice.org/wiki/Saving_a_document
https://wiki.openoffice.org/wiki/API/Tu ... PDF_export
viewtopic.php?f=9&t=2551
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.
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.
Re: Calc: Macro for 'Save a Copy'
Thank you for the amazingly quick reply!
I got it working. Here is the code if anyone is interested:
I got it working. Here is the code if anyone is interested:
Code: Select all
Sub Main
dim document as object
dim cell as object
document = ThisComponent 'assigns the current document to the variable document
Sheets = document.Sheets 'get the container of all Sheets
Sheet = Sheets.getByName("data") 'get the sheet named data
Controller = document.getcurrentController
Sheet.IsVisible = True
Controller.setActiveSheet(Sheet)
Dim Propval(1) as New com.sun.star.beans.PropertyValue
Propval(0).Name = "FilterName"
Propval(0).Value = "Text - txt - csv (StarCalc)"
Propval(1).Name = "FilterOptions"
Propval(1).Value ="44,34,0,1,1" 'Delimiters: ASCII 44 = , 34 = "
Doc = ThisComponent
GlobalScope.BasicLibraries.loadLibrary("Tools")
FileName = Tools.Strings.DirectoryNameoutofPath(ThisComponent.getURL(),"/") & "/schedule.csv"
FileURL = convertToURL(FileName)
Doc.storeToURL(FileURL, Propval())
Sheet = Sheets.getByName("main") 'get the sheet named main
Controller.setActiveSheet(Sheet)
End Sub
LibreOffice Version: 5.1.6.2 on Ubuntu 16.04