Using Macros in LibreOffice

Original author: Jack Wallen
  • Transfer
Habravchane, I want to present you a translation from the user rze . He is not yet on Habrahabr, but he would not refuse an invite. You can send it to mail@worze.org.

APD: thanks Mithgol , invite received. :)

Hello, harazhiteli!
Today I want to tell you about the use of macros in LibreOffice.

Foreword
Every day at home and at work, we use office applications to perform any tasks. It often happens that you specialize in one job and, as a result, perform the same tasks: insert the same text, format it using a large number of hot keys. In all these cases, you can save your valuable work time by automating some of your work.
Later in the article I will tell you about the use of macros in LibreOffice.

What are macros and why are they?

A macro is a sequence of specific actions that can be recorded using the regular menu. When you select a macro record, the actions you perform are automatically saved as script code. And in your further work, it will already be carried out independently, repeating exactly your actions in the program. A macro can be either simple or very complex - it all depends on what kind of result you need to achieve. The main criteria that apply to macros is to be powerful and at the same time easy to use. LibreOffice macros meet exactly these requirements. Let's try it in practice.

To use the packageLibreOffice, you need to have a pre-installed Linux, Windows or MacOS operating system, as well as the installed LibreOffice package (you can install it, for example, from ppa repositories, as described in this topic)

Macro control

Before we start creating our macro , we need to get acquainted with the macro management tool. We go along the path Tools - Macros - Organize Macros - LibreOffice Basic Macros (Service - Macros - Macro Management - LibreOffice Basic Macros):


In the left column of the window we can see the list of installed macros by default. By clicking on any of them, you can edit or delete it.
The main task of the window- select the macro you need, assign it a button on the toolbar or associate it with an event. Assigning buttons to a macro allows you to quickly execute the most commonly used buttons.

I want to note that creating a macro in automatic mode (recording) involves at least a little knowledge of the language for writing macros, since sometimes we need to edit it. In order to see what a macro looks like, select the macro we need and click Edit . The following is an example of what a macro looks like in the source code:



Next, consider recording macros.

Let's take a simple example. We have some text already inserted in the document and we need to make a headline for it, since our text will be used in business correspondence.
Our future macro will have to be able to:
- position the text at the top center of the page;
- enter the text, which will be used as the title.
After we create the macro, we will assign it a button on the toolbar. After that, one click of the mouse will be enough to insert the title into the document.
Let's follow the sequence of steps.

Step 1.
Open a text document. Let's go Tools - Macros - Record Macro . A small “Macro Recording” window will appear with one single “ Stop Recording ” button :

Step 2.
Create a text title. Click on the “Center alignment” button("In the center"), so that our future text is precisely in the center of the document. Now we write the title text itself. You should not set different formats for it (font or bold / italic / underlined), since the macro does not remember such actions.

Step 3.
After the creation of the header is completed, click on the “Complete Macro” button of the “Macro Recording” window. The Macro Organizer window appears immediately. Name the new macro (for example, PostHead). Now you can save it to the place you would like (for example, the " My Macro " folder ).

Step 4.
Now we have to add a toolbar button for a macro PostHead . This process is not as simple as it would seem at first glance.
OpenLibreOffice Basic Macros, click the " Assign " button . The next Customize window will appear , in which we should go to the Toolbars tab and make sure that “Standard” ( Standart ) is in the “Toolbar” field .




Click in the window the button "Add» ( the Add ). You will see another window - "Adding commands» ( the Add commands The ).
In the left window "categories» ( the Category ) find " the LibreOffice Macros"(at the very bottom of the list). We open it and get to our macro. As soon as we find it, it remains to complete the last and easiest step. Drag the Letterhead macro to the place on the toolbar where we would like to see it.
That's all, we coped with the task .
Now all we need to do - is to use the button PostHead, . we have added to the panel, for example, open a new document and press the button PostHead Our macro will create the header, it is with the text that we are "assigned" to him and place him at the top. the document is exactly centered .
True convenient?

Summary
Of course, in my example, we created a very simple macro. But with the above tools you can create very complex macros. And not only in Writer , but also in all other applications of the LibreOffice package (Spreadsheet, Presentations, etc.). Now that you know how to create macros, you can easily create your own in order to facilitate your work.
The purpose of this article is to learn the basics of working with a macro recording tool.

Also popular now: