Is it possible to share a single macro instance between multiple certain workbooks?

Have a large complex macro that is used in half dozen or so workbooks. Tired of managing the macro in each of them individually. Would like to have the macro used from one common place by each of the workbooks.

Brief search came up empty.

Templates. Store document specific macros in templates, so each document gets its own specific set of required macros.

Have not looked into using templates as don’t think that is the solution I’m seeking. Seems that would be for creating new documents from a template and the new document would naturally have the macros in the template.

This is about having existing documents use a macro from a common maintained source every time they are opened. So any changes to the common source are automatically picked up by each of the documents the next time they are opened.

If using templates is a solution for this could you please elaborate further.

Thanks.

Hi,

that common place is the MyMacros container, Standard library. Thus the macro becomes available for all and any opened LibreOffice document.

Just copy your macro there (and, after some checking, remove it from the documents it is written in). Depending upon the way your documents call it, you might have to adapt that call (toolbutton action, menu entry, and so on, so that now it points to the MyMacros/Standard/Whatever subprogram). Also, perhaps some other checks are to be added, just to ensure the macro can only be started for relevant documents and not for others.

This won’t help of course if the documents need to be shared. A different user profile would need to be “enriched” with the macro then before it can be used.
Another issue might be a possible call to the macro for a document not made for it. Damage?
Specialized document macros come with problems of different kinds and may sometimes be poisonous in different ways.

This is doable. Though was hoping for a solution in which the macro is only seen within the certain specific documents. Also as Lupp points out this only works for the user profiles that have the macro. That’s not a significant issue in this case. But would be nice if the macro was embedded in the document.

Was hoping for something that work like the document automatically importing a .bas file. Could a macro import a .bas? So main() imports .bas and call main_2() which is imported with .bas?
Then when document is saved, the macro is embedded and can be used by anyone.

You can copy macros into a file by macros.

Maybe these old threads help you.
https://forum.openoffice.org/en/forum/viewtopic.php?p=519520#p519520
https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=95833
https://forum.openoffice.org/en/forum/viewtopic.php?t=37459

So, IIUYC, you’re looking for a solution that would allow to have macros embedded within a set of given documents and which could be easily updated whenever necessary.

A solution could be to have a tool that can copy a (set of) macros from any container to any other.

I happen to be currently working on such a tool (a Writer template) named TheLOBSTER (the LibreOffice BASIC Script Transfer tool). If you’re interested in testing it, feel free to contact me off-list (note: TheLOBSTER is currently in French; translation to EN is due).

1 Like