I am converting an Excel Macro to Calc and I would like to know how to open a SaveAs dialog box so the user can enter a file name and file location.
As I have just started using Calc. I am not sure of the exact requirements for writing Macros. I have installed the latest SDK, I am also looking for more information on what the methods and properties are. The help in Calc is very limited compared with Excel
All the Excel code is below.
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Explicit
Sub saveAsText()
Dim strFilename As String
Dim fName
Dim rngRow As Range
Dim fh
Dim strLine As String
Dim rngCell As Range
fName = Application.GetSaveAsFilename
If fName = False Then Exit Sub
fh = FreeFile
Open fName For Output As fh
For Each rngRow In ActiveSheet.UsedRange.Rows
strLine = ""
For Each rngCell In Intersect(rngRow, ActiveSheet.UsedRange)
If strLine <> "" Then
strLine = strLine & ","
End If
strLine = strLine & """" & CStr(rngCell.Value) & """"
Next rngCell
Print #fh, strLine
Next rngRow
Close #fh
End Sub
Thanks,
Ivan
[Solved] How to open a SaveAs dialog box in calc macro
[Solved] How to open a SaveAs dialog box in calc macro
Last edited by icarey on Fri Jul 25, 2008 9:12 am, edited 2 times in total.
OOo 2.4.X on Ms Windows XP
Re: How to open a SaveAs dialog box in calc macro
Intanciate a FilePicker service
OOo makes use of 11 predefined file picker templates. You set the dialog's template by calling a intitialization routine with an array of one of the template constants 0 to 10.
Templates 1, 2, 3, 4, 5, 6 and 10 are for saving files (constants named c.s.s.ui.dialogs.TemplateDescription.FILESAVE_...), the others are templates for file-open dialogs (constants named c.s.s.ui.dialogs.TemplateDescription.FILEOPEN_...).
Testing all the templates:
Method execute() returns one of dialog results for OK or Cancel (1 or 0).
Method getFiles() returns an array of file-URLs even if multiple selection is disabled.
http://api.openoffice.org/docs/common/r ... le-ix.html
Code: Select all
oFP=createUnoService("com.sun.star.ui.dialogs.FilePicker")
Code: Select all
oFP.initialize(Array(com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE))
Testing all the templates:
Code: Select all
Sub test_FilePickerTemplates()
for i = 0 to 10
oFP=createUnoService("com.sun.star.ui.dialogs.FilePicker")
oFP.initialize(Array(i))
iExec=oFP.execute()
REM if not canceled ...
if iExec = 1 then
aURLs=oFP.getFiles()
msgbox aURLs(0)
endif
next
End Sub
Method getFiles() returns an array of file-URLs even if multiple selection is disabled.
http://api.openoffice.org/docs/common/r ... le-ix.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice