How can I call a macro from a library from a file macro?

I have macro ‘foo’ in ‘Module1’ of library ‘General’:
My macros and dialogs/General/Module1/foo

foo is declared public.

I have a macro ‘bar’ in ‘Module1’ of library ‘Standard’ of file ‘myfile.ods’:
myfile.ods/Standard/Module1/bar

I want bar to call foo but LibreOffice complains that foo does not exists.
How can I do that?

Thanks

See this discusssion in a much better structured forum.

It was concerned with Apache OpenOffice but things should be the same insofar with LibO.

You will have to open myfile.ods first by your code using StarDesktop.LoadComponentFromURL().
See this post.

When the LO program starts up it loads the Library Standard in My Macros. As you have created another Library General containing foo this Macro can not be found as the Library General has not been loaded. You need to explicitly load the General Library using -


Sub LoadLib
GlobalScope.BasicLibraries.loadLibrary("General")
End Sub

Similarly if you have Macros in your database document (myfile.ods) they should be in the Standard Library as this Library is loaded when you open the document. If you create another Library in your database document then you will need to load this explicitly too.

If you put the Macro Sub LoadLib above in the Standard Module of your document you can have this execute when you open the document by having it run from the “Open Document” event for the document.

Also if you are having more than one Module being loaded make sure you do not use the same name for a Macro in both Modules as it will obviously crease a conflict in names.