Operation Manual
Introduction
A macro is a saved sequence of commands or keystrokes that are stored for later use. An example
of a simple macro is one that “types” your address. The LibreOffice macro language is very
flexible, allowing automation of both simple and complex tasks. Macros are very useful when you
have to repeat the same task in the same way over and over again.
LibreOffice macros are usually written in a language called LibreOffice Basic, sometimes
abbreviated to Basic. Although you can learn Basic and write macros, there is a steep learning
curve to writing macros from scratch. The usual methods for a beginner are to use macros that
someone else has written or use the built-in macro recorder, which records keystrokes and saves
them for use.
Most tasks in LibreOffice are accomplished by “dispatching a command” (sending a command),
which is intercepted and used. The macro recorder works by recording the commands that are
dispatched (see “Dispatch framework” on page 345).
Your first macros
Adding a macro
The first step in learning macro programming is to find and use existing macros. This section
assumes that you have a macro that you want to use, which may be in an email, on a web page, or
even in a book. For this example, the macro in Listing 1 is used. You must create a library and
module to contain your macro; see “Macro organization” on page 346 for more information.
Listing 1: Simple macro that says hello
Sub HelloMacro
Print "Hello"
End Sub
Figure 333: LibreOffice Basic Macros dialog
336 | Getting Started with LibreOffice 4.0