LibreOffice Macro Organization


This tutorial will share the basic idea on LibreOffice Macro file structures and organizations which can be used to export or share LibreOffice Macro as part of the office file.

If you are familiar with M$ Excel VBA or VBA in general, you would know that the VB codes of a macro resides in a VB project and if you want to include the macro inside the excel for example, you have to save the file as a xlsm format which tells that the file contains macros.

LibreOffice Macro File Default Structures

Well, for LibreOffice, the process is definitely possible and it is organised in a different matter.
When you first create a Macro, by default LibreOffice creates it under a path : My Macros -> Standard -> Module1. All of your macro functions are resides under Module1. For this tutorial, I have created a function my_macro which resides under Module1.

LibreOffice 4 keeps all the macro codes which is created under default Module1 in path /home/[user name]/.config/libreoffice/4/user/basic/Standard.

LibreOffice macro path debugpoint 1

Inside the path, there should be a file called Module1.xba which contains your actual default macro functions. The test function my_macro and its contents should be inside this file.

module1 xba contents debugpoint com 2

How to Create Macros as part of the Office File

If you have written lots of macros and functions using above default file structure and save the file, the macros will not be saved along with the same file. If you distribute or send this file to someone else, they will not see the macros when they open the file. Because the macro contents remains in the disk where it has been coded/developed.

If you want to distribute or send the LibreOffice file (Calc, Impress etc) with the macro functions, modules you have to create the macros in a different way.

While creating macros and dialog which you want to distribute as part of the LibreOffice file, you have to create the macro inside the file. Open the dialog from Tools -> Macros -> Organize Macros -> LibreOffice Basic. Inside the dialog, select the file name in the left side under label ‘Macro From’. Press ‘New’, LibreOffice will ask for a module name.

create macro debugpoint com 3

As default “Module1” is already in use by LibreOffice, type any name you want and press OK (I have used debugpoint_demo_module as module name for this tutorial).

New Module debugpoint com 4

Once that is done, the macro editor will open with your new module and macro under your working file. Now you can write as many macros you want under current module and save the working LibreOffice file. Once the file is saved, all the macros and its contents is saved along with the file and you can easily share or distribute the file to users.

macro editor debugpoint com 5

Containers – Libraries – Modules – Macros

Macros are stored under Modules in LibreOffice. Modules are part of Libraries and Libraries are part of containers as shown in below image.

LO mac org 6

Loading the user defined Module

By default, LibreOffice assumes all the dialogs, variables are from “Module1” as per default organization. But we have created a new module named “debugpoint_demo_module” which remains along with the file itself. You need to load the module before you start writing macro codes. You can load the user defined modules using below method:


If you also created a dialog – say “my_dialog” under the working file itself, you can create the dialog object using below:

Dim oDialog1 As Object
oDialog1 = CreateUnoDialog(DialogLibraries.Standard.my_dialog)

Enabling Macro in LibreOffice Files

After you distribute or share the LibreOffice file with the macro in it, user may face below error when opening the file in corresponding system. Macro execution is disabled by default in LibreOffice due to security reasons.
err 1
err 2

As instructed, go to Tools -> Options -> LibreOffice -> Security -> Macro Security. By default, the macro security is set to ‘high’. You can mark it as ‘low’ if you trust the source of the macro and save. Then you can try executing the macro.
sec 1
sec 2


This summarises how to create your own macro and save it along the file to distribute. If you are facing problem to follow above tutorial drop a comment using comments box below. For more LibreOffice macro tutorials, go to top menu and find the macro tutorial index.


Looking for Something Else?

If you are looking for something else in LibreOffice macro tutorials, Or, wants to learn more about it, please follow below link for complete Macro Tutorials Index:

LibreOffice Macro Tutorial Index

You may also like...

  • Shadmeister


    Where is the text for loading the library placed?

    You cannot place it in the module that is encapsulated in the file, as this is never loaded until you use the directive to load the module.



Translate »