Running a macro on Open Document Events

LibreOffice Calc on Windows. I have created a simple macro. I would need it to be executed on an Open Document event, not only on my machine, but also on recipients.

Does it make a difference if a macro is in “My Macros & Dialogs”, or should it be in filename.ods hierarchy tree?

In Tools → Customise the only option in the “Save in:” dropdown many is LibreOffice. Should there me also e.g. the document only? Possibly related, choosing “Open Document”, and Assign: Macro… only shows the macros under “My Macros”. Not e.g. if I have a Macro in the document itself, the macro has to be in “My Macro & Dialogs”.

Macros stored to My Macros and Dialogs reside in a folder of the current user profile in the user’s file system. They are therefore not available on the recipients’ different computers an their LibreOffice installs.
Macros stored to the tree designated by the filename are actually stored to that file, and therefore accessible on any recipient’s system. However, no user should be encouraged to permit the execution of such macros without stringent checks for the absence of malign or dangerous code.
If the recipients of your Calc documents are capable of performing such checks, and ready to take the time for them, I cannot know.
If a specific community of users need to run the same macros again and again, they should get the macros as textual content of a special document, and be advised to check them once, and then to store them to specific modules of their Standard library. They are then callable via document events (like onViewCreated), but recipients not having installed them properly are excluded from the usage.
The author of such macros has, of course, a kind of responibility for maintenance and updates, but hasn’t any guarantee that users won’t tamper with the code. He (f/m) may therefore prefer to distribute them as an extension which mode supports maintenance and code protection in a standardized way.

Thank you for your answer. This is what I suspected. And yes, I understand the security concerns, I’m just trying to figure out how the macros work in LibreOffice. I need to next figure out how to have a macro as part of the file and have it automatically execute during Open Document event. I have set the security level on my LibreOffice to allow that. Again, understand it as a general feature risky, but right now even for legitimate uses I haven’t been able to figure out if / how it is possible.

Store the code embedded in the document.
Call Tools>Customize… tab “Events”.

See attached example.
disask105511EmbeddedOnViewCreatedExample.ods (156.0 KB)

sounds like security level as e.g. Enable macro - LibreOffice 5.0.4.2

https://help.libreoffice.org/latest/en-US/text/shared/optionen/macrosecurity.html