[Solved] How to open a SaveAs dialog box in calc macro

Creating a macro - Writing a Script - Using the API

[Solved] How to open a SaveAs dialog box in calc macro

Postby icarey » Mon Jul 21, 2008 10:32 am

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

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
Posts: 1
Joined: Mon Jul 21, 2008 10:24 am

Re: How to open a SaveAs dialog box in calc macro

Postby Villeroy » Mon Jul 21, 2008 4:04 pm

Intanciate a FilePicker service
Code: Select all   Expand viewCollapse view

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.
Code: Select all   Expand viewCollapse view

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:
Code: Select all   Expand viewCollapse view
Sub test_FilePickerTemplates()
for i = 0 to 10
    REM if not canceled ...
    if iExec = 1 then
      msgbox aURLs(0)
End Sub

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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Posts: 29262
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests