Just like the Basic language itself, the hierarchy of Basic containers, libraries and modules is difficult to understand.
The containers [LibreOffice Macros] and [My Macros] are GlobalScope, the union of all publicly accessible Basic libraries.
[LibreOffice Macros] resides read-only in the installation directory accessible to all users of the local machine, whereas [My Macros] resides in the user profile. [My Macros] is the place where the logged in user can read and write his own coding. Putting the rule to the test: Try to add a new library named “Tools” to [My Macros] fails because a library with that name exists in the same name space but under [LibreOffice Macros]. Use some other name such as “MyTools” for your own tools in [My Macros]
You load any of these libraries with GlobalScope.BasicLibraries.loadLibrary(sLibName).
Basic libraries that are embedded in documents have their own name space within each document. You load them without GlobalScope like this:
Sub Main
REM load Library1 embedded in ThisComponent and execute Main on Module1
ThisComponent.BasicLibraries.loadLibrary("Library1")
Library1.Module1.Main
End Sub
You do not have to load any library explicitly when Library1.Module1.Main is triggered by some script event, push button, toolbar etc. All these UI elements load libaries as needed. You only need to call loadLibrary(sLibName) when your code calls a library that is not yet loaded like the above example does.
The special library named “Standard” is loaded with the containing document. [My Macros].Standard is loaded with the office suite. “Standard” is a scratch pad for experimental code. Any code you may want to export to some other office installation via reference or via extension package should be stored in a library other than “Standard” unless you are willing to transfer code by means of copy&paste.