0% found this document useful (0 votes)
5 views4 pages

Macros Notes

Uploaded by

bindugopakumar70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Macros Notes

Uploaded by

bindugopakumar70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PART B – UNIT 2 – Using Macros in Spreadsheet.

A macro is a single instruction that executes a set of instructions. These set of


instructions can be a sequence of commands or keystrokes that can be used for any
number of times later. A sequence of actions such as keystrokes and clicks can be
recorded and then run as per the requirement.

By default the macro recording feature is turned off. Macro recording can be
enabled using the Tools option on the main menu bar by selecting Tools > Options
> LibreOffice > Advanced. Observe the Optional Features. There are two options
which are not check marked. Put the checkmark on the option “Enable macro
recording”.

The Macro records all the keyboard and mouse actions but the following actions are
not recorded.

• Opening of windows

• Actions carried out in another window than where the recording was started.

• Window switching

• Actions that are not related to the spreadsheet contents.

• Selections are recorded only if they are done by using the keyboard but not when
the mouse is used.

• The macro recorder works only in Calc and Writer.

To record a macro.

Step 1. Click on Tools > Macros and then click on the Record Macro option.

Step 2. Now start taking actions that will be recorded.

Step 3. Once you click on Record Macro option, recording of actions starts and a
small alert will be displayed Clicking on “Stop Recording” button will stop the
recording of actions.

Step 4. This will open the Basic Macros dialog window to save and run the created
macro.
Step 5. To save the macro, first select the object where you want the macro to be
saved in the Save Macro to list box.

Step 6. The name of the macro by default is Main and is saved in the Standard
Library in Module1. You can change the name of the macro.

Step 7. Click on Save button.

A Library is a collection of modules which in turn is a collection of macros.


The recorded macro is internally stored as instructions written in a
programming language that are executed when the macro is executed or run.
Rules for naming a Macro, Module or a Library:
While naming a Macro, Module or a Library the name should :
• Begin with a letter
• Not contain spaces
• Not contain special characters except for _ (underscore)
Running a Macro
To run a macro:
Step 1. Type the heading in cell A1
Step 2. Use Tools > Macros > Run Macro to open the Macro Selector dialog box
shows three names in the library. Out of which
• LibreOffice Macros library is provided by LibreOffice and contains modules
with pre recorded macros and should not be changed.
• My Macros contain macros that we write or add to LibreOffice.
• The name of the worksheet we are working on. Since at this time we have
not
saved the worksheet with another name it is showing Untitled1.
Step 3. Select the library and module in the Library list.
Step 4. Select the macro in the Macro name list.
Step 5. Click Run to run the macro.

Creating and Organising a Simple Macro


To organize the macro:
Step 1. Click on Tools > Macros > Organize Macros > LibreOffice Basic to open the LibreOffice Basic
Macro dialog window
Step 2. Click Organizer to open the Basic Macro Organizer dialog.
Create a library to store a macro
To create a new library containing modules, click on Library > New. Use the
following steps to create a module to store a macro.
Choose the Modules Tab and select a Module.
Click on New to create a new Module.
Macro as a Function
A function is a line of code that executes when you call it. When you invoke a
function it returns a value. To define the macro as a function , use the keyword
Function. The syntax to define a simple macro is :
Function function_name()
Body of the function
End Function
Example :
Function school()
School()=”CHINMAYA VIDYALAYA”
End Function
To write the macro function :
1. Open the Basic macro dialog box using the command
Tools  Macros Organize Macros  Basic
2. Click any one macro name and click Edit
3. Now the My macros code window will open, click an empty space and type
the code.
4. Save the code by pressing Ctrl+S or File  Save command.
Passing arguments to the function
The values passed to a function are called arguments. To pass arguments to the
function write the code :
function function_name(optional <arguments name>)
Body of the function
end function
Example :
Function square(optional x)
square=x*2
End function
=square(8) will display 16 in the cell.

You might also like