Recording a Macro in OpenOffice

By | December 14, 2015

Repeating tasks in OpenOffice Calc, or any other spreadsheet application, can be a tedious process. For example, if you want to sort a group of cells based on a custom order, you would have to do the following:

  1. Select a range of rows and columns
  2. Click Data
  3. Click Sort
  4. Select key #1
  5. Click the options tab to select “Custom sort order”
  6. Etc.
  7. Click “OK”

Each time you want to re-sort the data, you have to perform the exact same steps over and over again.

Macros in OpenOffice Calc allow you to save time by recording a group of instructions so they can be played back automatically.

Enable Macros

Macros in OpenOffice are considered an “experimental feature” and are not enabled by default. To enable macros go to:

Tools -> Options -> LibreOffice -> Advanced

Check off “Enable experimental features” and “Enable macro recording” and click OK.

calc_enable_experimental_features

Record a Macro

When you have memorized the steps to perform your task go to:

Tools -> Macros -> Record Macro

A little window will pop-up showing that your actions are now being recording.

calc_macro_recording

Start performing the work you normally do. OpenOffice will record the steps you take as you go. When you’re finished, click on “Stop Recording”.

A window will appear where you can name and save your new macro.

calc_save_macro

The next time you need go through the same steps, you can simply run the macro and it will do all the repetitive work for you.

To run a macro, go to:

Tools -> Macro -> Run Macro

Assign Macros to Events

You can assign macros to events that occur while you are working on the document. For example, a macro could be configured to run whenever you close a document.

You set this up by going to Tools -> Macros -> Organize Macros -> LibreOffice Basic

Select an existing macro and click the “Assign” button.

Click the “Events” tab and select the event that you’d like to assign the Macro to. For example, the “Close Document” event.

calc_macro_events_tab

Click the “Macro” button under Assign.

Find the Macro you created, which is probably under My Macros -> Standard -> Module 1.

Select it and click OK.

Test that the Macro is working properly by executing the event that triggers it.

The Code Behind Macros

The programming language behind OpenOffice macros is called BASIC.

If you’d like to see the code behind a macro, go to:

Tools -> Macros -> Organize Macros -> LibreOffice Basic

Find your macro, select it, and click the “Edit” button.

calc_macro_code

 

Leave a Reply

Your email address will not be published.

*