Libreoffice base - How to open a file without an absolute hyperlink?

I have come across a method to open an internal form using a macro with ThisDatabaseDocument.FormDocuments, however, I want to open a calc file in the same folder as the database, and regardless of what folder that is, so the database can be moved or opened on other computers and still work. How can I refer to the folder the database is in to link files from it?


Here is one tested method:

Option Explicit
Sub getPath
    Dim sCalcFile As String
    Dim sAbsolutePath As String
    sCalcFile = "YOUR_CALC_FILE_NAME.ods"
    If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
    End If
    sAbsolutePath = DirectoryNameoutofPath(ThisComponent.Parent.getURL(), "/") & "/" & sCalcFile
Rem Can open on Linux Ubuntu with
    Shell ("bash -c 'soffice " & sAbsolutePath & "'")
End Sub


You can also move the resulting path to a Button set with Action = Open document/web page. Code for that can be found on this post → How can a value be passed to URL in LO Base Form