Operation Manual

8) Select Module1, or the new module that you created, and click Edit to open the Integrated
Debugging Environment (IDE) (Figure 335). The IDE is a text editor included with
LibreOffice that allows you to create and edit macros.
9) When a new module is created, it contains a comment and an empty macro named Main,
which does nothing.
10) Add the new macro either before Sub Main or after End Sub. Listing 2 shows the new
macro has been added before Sub Main.
11) Click the Compile icon on the Macro toolbar to compile the macro.
12) Place the cursor in the HelloMacro subroutine and click the Run BASIC icon on the
Macro toolbar, or press the F5 key, to run the HelloMacro in the module. A small dialog will
open with the word “Hello” displayed. If the cursor is not in a subroutine or function, a
dialog will open; select the macro to run.
13) Click OK to close this small dialog.
14) To select and run any macro in the module, click the Select Macro icon on the
Standard toolbar or go to Tools > Macros > Organize Macros > LibreOffice Basic.
15) Select a macro and then click Run.
Listing 2: Module1 after adding the new macro.
REM ***** BASIC *****
Sub HelloMacro
Print "Hello"
End Sub
Sub Main
End Sub
Recording a macro
If you have to repeatedly enter the same information, you can copy this information after it has
been entered into your document for the first time, then paste the information into your document
each time you want to use it. However, if something else is copied to the clipboard, the contents on
the clipboard are changed. This means that you have to re-copy your repeated information. To
overcome this problem, you can create a macro that enters your repeated information.
Note
For some types of information that you want to repeatedly enter into a document, it
may be more convenient to create an AutoText file. See the Writer Guide Chapter 3
Working with Text for more information.
1) Make sure macro recording is enabled by going to Tools > Options > LibreOffice >
Advanced on the main menu bar and selecting the option Enable macro recording. By
default, this feature is turned off when LibreOffice was installed on your computer.
2) Go to Tools > Macros > Record Macro on the main menu bar to start recording a macro.
A small dialog is displayed indicating that LibreOffice is recording a macro.
3) Type the desired information or perform an appropriate series of operations. As an
example, type your name.
4) Click Stop Recording on the small Recording dialog to stop recording and the LibreOffice
Basic Macros dialog opens (Figure 333 on page 336).
5) Open the library container My Macros.
6) Find the library named Standard in My Macros. Note that every library container has a
338 | Getting Started with LibreOffice 4.0