Greetings, thanks to this forum some of the solutions to my issues were found but except for a very simple feature that I could not done properly
I'm totally new with OOo BASIC, I had being trying to find a template that calls upon a Save As Dialog box that other BASICS I used to before have
Filename = "C:\..\file location\..\Export.xml" ' This method fixed the location where my export goes to
FileNo = FreeFile
Open Filename For Output As #FileNo
Print #FileNo "<List>"
Call printlist
Print #FileNo "</List>"
Close #FileNo
Above creates an Export.xml at a fixed location specified in code. It temporary allows me to continue my work but it is not the solution I need. I want to achieved a save as dialog box will prompt the user to choose a file location and file-name like normal save as dialog box with extension filter would be nice. Additionally I need to be able to do an Open file as well like normal open dialog box. Not an automated process like most solutions I found in the forum, but a prompt when it came to this part of the code.
Thanks in advance.
Last edited by stevetronik on Wed Dec 08, 2010 3:26 am, edited 2 times in total.
Andrew Pitonyak has a macro based on the FilePicker dialog for this purpose.
As the name suggests it only picks the filename. It is your decision if you use the name for opening a file or for saving it.
'Opens a Open File Dialog to allow the end user to select a file to import into the program.
'This code is from Andrew Pitonyak's free Useful Macros book
Function fOpenFile() as String
Dim oFileDialog as Object
Dim iAccept as Integer
Dim sPath as String
Dim InitPath as String
Dim oUcb as object
Dim filterNames(3) as String
filterNames(0) = "*.*"
filterNames(1) = "*.png"
filterNames(2) = "*.jpg"
GlobalScope.BasicLibraries.LoadLibrary("Tools")
'Note: The following services must be called in the following order,
' otherwise the FileDialog Service is not removed.
oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
AddFiltersToDialog(FilterNames(), oFileDialog)
'Set your initial path here!
InitPath = ConvertToUrl("C:\Pictures")
If oUcb.Exists(InitPath) Then
oFileDialog.SetDisplayDirectory(InitPath)
End If
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
fOpenFile = sPath
End If
oFileDialog.Dispose()
End Function
Sub TestFilePicker()
Dim sFilename As String
sFilename = fOpenFile()
MsgBox sFilename & chr(10) & ConvertFromUrl(sFilename)
End Sub
You want to use the filename with Open, hence you need the name in OS notation while the file picker macro always returns it in URL notation. But ConvertFromUrl is your friend here.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
in case someone is looking for SaveAs dialog as many solutions points towards filepicker which is obvious in making Open dialogs below is the code I used for Save As
Function fSaveFile() as String
'Set the Dialog Arguments to a Template for FILESAVE
sFilePickerArgs = Array(_
com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION )
'register the Service for Filepicker
oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
'Pass some arguments to it
With oFilePicker
.Initialize( sFilePickerArgs() )
.setDisplayDirectory( "C:/" )
.appendFilter("XML Files (.xml)", "*.xml" )
.setTitle( "Save As ..." )
End With
'If the savepath is selected return the complete path and display it in an messagebox
If oFilePicker.execute() Then
sFiles = oFilePicker.getFiles()
fSaveFile = sFiles(0)
' MsgBox( sFileURL )
End If
' Close the Dialog
oFilePicker.Dispose()
End Function