LO Help claims about CHDIR that “This statement currently does not work as documented”. How can I change current directory at runtime? I use LO 6.3.6.2, Windows and Linux.
Depended on the fact what you want to achieve really, there are some tips for you:
-
If this question is related to the macro programming (I supposed it based on the “runtime” word), and you want to load or save a document onto a different place, then you need to use a different path (a different URL) for your file.
-
If the question is related to the default “Save as” path (what is the “Documents” in the Windows): you can modify the default path of the documents in the settings. (You can do it manually or programatically.)
I suggest you to use the Open/Save dialog boxes of the LibreOffice instead of the dialog boxes of the operating system. You can change it in the settings.
Here is a sample file, embedded your modified macro code inside.
Thanks, Tibor! Let me clarify the question. I want to select a file from a specific directory. I try to use a function ChooseAFileName from Andrew Pitonyak’s “OpenOffice.org Macros Explained”. I inserted one line to his macro to point to the desired directory. It doesn’t work, another directory is displayed.
Sub Main
print ChooseAFileName
End Sub
Function ChooseAFileName() As String
Dim vFileDialog
Dim vFileAccess
Dim iAccept as Integer
Dim sInitPath as String
vFileDialog = CreateUnoService(“com.sun.star.ui.dialogs.FilePicker”)
vFileAccess = CreateUnoService(“com.sun.star.ucb.SimpleFileAccess”)
'Set the initial path here!
CHDIR("C:\DDD\BR180813\TXT") ' THIS IS MY LINE
sInitPath = ConvertToUrl(CurDir)
If vFileAccess.Exists(sInitPath) Then
vFileDialog.SetDisplayDirectory(sInitPath)
End If
iAccept = vFileDialog.Execute()
If iAccept = 1 Then
ChooseAFileName = vFileDialog.Files(0)
End If
vFileDialog.Dispose()
End Function
Here is an useful decription about the FilePickers and about the FolderPickers:
See my Answer above:
There is a new sample file uploaded, embedded your modified macro code.
Thank you very much !