Subject specific skill
Ln:5, Using Macros in a Spreadsheet
Introduction
Macros features of Calc are a set of actions or instructions that you record to perform repeatedly in a
spread sheet.
It is a single command that represents series of action or instructions.
It recorded by the user to automate repetitive tasks.
You can run a macro as many times as you want.
Once you created a Macro need not to do the task manually
A Macro automatically do the recorded actions and save your time and effort.
It is very useful when you want to do repetitive tasks
Actions which are not recorded by macros
Opening windows
Action carried out in another windows
Window switching
Actions that are not related to the document.
Record only instruction given by keyboard
Steps to enable a new Macro recorder
Tools menu
Select options
Click on Libre office > Advanced
Enable macro recording option
Click on ok
now, you can record macro in Calc
Steps to run a Macro
Tools menu
Choose macros> Run macro
Macro selector dialog box opens
Select your macro that already recorded
eg: my macros > standard >Header >macro
Steps to Creating and Organizing Macros
Tools menu
Choose Macros > Organise Macros
Choose LibreOffice Basic in submenu
LibreOffice Basic dialog box opens
Click on organizer button
LibreOffice Basic Macro Organizer dialog box opens
Choose the Libraries
Select the spread sheet
Click on New button
The New Library dialog box opens
Enter the name for Library, click ok
Select the Library name and click on Edit
LibreOffice Basic Text Editor opens
Calc automatically creates a module named Module1 and Macro named main
1
Subject specific skill
Ln:5, Using Macros in a Spreadsheet
Enter the code for Module1
Save it
Run macro, result in pop-up window
Syntax to define a simple function without parameter
Function Function_Name( )
Body of Function
Function_Name=Result
End Function
Using a Macro as a function
A function is a line of code that executes when you call it
When you invoke functions
It returns value
Steps to create a macro as a function
Tools menu >Macros >Organize Macros
Select LibreOffice Basic in submenu
LibreOffice Basic Macros dialog box opens
Click Organizer button
LibreOffice Basic Macro Organizer dialog box opens
Choose Libraries tab and select spreadsheet contains the macro
Click New button
New Library dialog box appears
Enter the name and click OK
Select the Library name in the library list
Click on Edit button
LibreOffice Basic Text Edtor opens
Calc automatically creates a Module and macro
Ener the code for Module
Save it
Enter the function in a spreadsheet
Syntax to define a simple function without parameters
A macro acts as a function.
you can pass arguments (values/ parameters) to a macro when you call it.
To allow a macro to accept a value, simply type a name for that value between the parenthesis at the
top of the macro
Syntax to define a macro with parameters (in a Text Editor)
Function Function_Name(optional parameters,optional parameters)
Program code
Function_Name=Result
End Function
Syntax to pass arguments to a macro while calling it(in a spreadsheet)
=Function_name(Parameter1,Parameter2)
Steps to pass arguments to a macro while calling it
Tools>Macros> Organize> LibreOffice Basic
LibreOffice Basic Macros dialog box opens
2
Subject specific skill
Ln:5, Using Macros in a Spreadsheet
Click on Organizer button and Module tab
Select Standard Library
Click on New button
New Module Dialog box appears
Enter a name for the module, click OK
Select the module name
Click on Edit button
LibreOffice Basic Text Editor opens
Enter the code to pass arguments
Save it
Call the macro and pass the defined arguments(in aspreadsheet)