I have an .odb file with macros in Basic. I also have a Basic macro library that I want to make available in LibreOffice - My Macros. I know that the content of this library is stored in the script.xlc file in the LO user profile. I have exported all the Basic macros (the entire library structure - folders and modules as .xba files) and also the script.xlc file in a backup folder. My plan is that when the .odb file is first opened, it checks for the presence of one of the libraries in My Macros, and if it's not there, it copies the script.xlc and dialogs.xlc files from the backup. This approach works well for me on macOS, but not on Linux; on Linux, the default script.xlc and dialogs.xlc files are always restored after closing the .odb and LibreOffice. Here is my piece of code; maybe you can see how to handle it. Thanks for your ideas
Code: Select all
ThisComponent.BasicLibraries.LoadLibrary("DataManagement")
ThisComponent.BasicLibraries.LoadLibrary("Opening")
If GlobalScope.BasicLibraries.hasByName("Tools") Then GlobalScope.BasicLibraries.loadLibrary("Tools")
If GlobalScope.BasicLibraries.hasByName("ScriptForge") Then
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Else
MsgBox ("Library ScriptForge is missing!", MB_ICONEXCLAMATION + MB_OK, "Warning Message")
End If
' Get current path
path = DirectoryNameoutofPath(ThisDataBaseDocument.getLocation() ,"/")
If Not GlobalScope.BasicLibraries.hasByName("DataManagement") Then
MsgBox ("Please close and restart MyAPP (exit LibreOffice) for the initial library initialization", MB_ICONEXCLAMATION + MB_OK, "Warning Message")
'Copying script.xlc from the backup folder to user/basic to make macros accessible in My Macros if the libraries were not found
Dim sourceDirectory As String
sourceDirectory = path & "/user/basic/backup_library_path/"
Dim scriptSourceFile As String
scriptSourceFile = "script.xlc"
Dim dialogSourceFile As String
dialogSourceFile = "dialog.xlc"
Dim destDirectory As String
destDirectory = path & "/user/basic/"
Dim scriptSourceURL As String
scriptSourceURL = sourceDirectory & scriptSourceFile
Dim dialogSourceURL As String
dialogSourceURL = sourceDirectory & dialogSourceFile
Dim scriptDestURL As String
scriptDestURL = destDirectory & scriptSourceFile
Dim dialogDestURL As String
dialogDestURL = destDirectory & dialogSourceFile
FileCopy scriptSourceURL, scriptDestURL
FileCopy dialogSourceURL, dialogDestURL
Exit Sub
Else
GlobalScope.BasicLibraries.LoadLibrary("DataManagement")
End If
If GlobalScope.BasicLibraries.hasByName("Opening") Then GlobalScope.BasicLibraries.loadLibrary("Opening")