Here is the code, which fits my needs: The first macro opens the file open dialog, where one can select an existing file. This file is then opened by the CSV-Filter with given defaults concerning encoding, delimiter etc. The next macro saves open the file save dialog, where one can select an existing file (which will be overwritten or specify a new file name). The active sheet is then exported as CSV with the same properties. It’s easy to get the properties specification, using the record macro feature and record a macro while a save-as-procedure.
Sub DDICSVopen
dim aUrl(), s$
Dim vDoc 'die geladene Komponente
Dim Arg()
dim fileProps(1) as new com.sun.star.beans.PropertyValue
fileProps(0).Name = "FilterName"
fileProps(0).Value = "Text - txt - csv (StarCalc)"
fileProps(1).Name = "FilterOptions"
fileProps(1).Value = "44,34,76,1,,0,false,true,true,false"
oDlg = createUnoService("com.sun.star.ui.dialogs.FilePicker")
oDlg.setMultiSelectionMode(false)
oDlg.execute
aUrl = oDlg.getFiles()
'Messagebox for debugging
's = "file:" & chr(10) & aUrl(0) & chr(10)
'msgbox s
vDoc = StarDesktop.loadComponentFromURL(aURL(0), "_blank", 0, fileProps())
End Sub
Sub DDICSVsave
dim aUrl(), s$
dim oDlg as variant
dim fileProps(1) as new com.sun.star.beans.PropertyValue
fileProps(0).Name = "FilterName"
fileProps(0).Value = "Text - txt - csv (StarCalc)"
fileProps(1).Name = "FilterOptions"
fileProps(1).Value = "44,34,76,1,,0,false,true,true,false"
oDlg = createUnoService("com.sun.star.ui.dialogs.FilePicker")
dim listAny(0) as variant
listAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE
oDlg.initialize(listAny()) ' Speichern unter
oDlg.setMultiSelectionMode(false)
oDlg.execute
aUrl = oDlg.getFiles()
thisComponent.storeAsURL(aURL(0), fileProps())
End Sub
This book helped:
Thomas Krumbein, 2007: Makros in OpenOffice.org – Basic/StarBasic, Galileo Press (http://www.worldcat.org/oclc/188235695)
Update: The updated version of DDICSVsave contains now an initialization which must not be missing in order to work with LibO 5.4. Credit goes to Regina Henschel who presented the solution here.