Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
Notes › Information Technology (402) › Ch 5: Using Macros
Class X · Part B – Unit 2: Electronic Spreadsheet (Advanced) — Calc · Hindi + English

Ch 5: Using Macros

What is a Macro?

Macro: a single instruction that executes a set of instructions — a recorded sequence of commands / keystrokes that can be run any number of times to automate repeated tasks.

Enabling & Recording a Macro

  1. Enable: Tools > Options > LibreOffice > Advanced > tick Enable macro recording (off by default).
  2. Tools > Macros > Record Macro.
  3. Perform the actions to be recorded.
  4. Click Stop Recording.
  5. In the Basic Macros dialog, choose the Library/Module, type a macro name and click Save.
Actions NOT recorded: opening windows; actions in another window; window switching; actions unrelated to sheet contents; selections made with the mouse (only keyboard selections are recorded). The recorder works only in Calc and Writer.

Running a Macro

Tools > Macros > Run Macro > expand the Library and Module > select the macro > Run.

Library, Module and Macro

Remember: a Library is a collection of Modules; a Module is a collection of Macros. The default macro is Main, saved in the Standard library, Module1.

Two containers appear: LibreOffice Macros (pre-recorded — do not change) and My Macros (macros the user writes/adds).

Macro written in BASIC

Macros are written in the BASIC language. Code begins with Sub <name> and ends with End Sub. Edit via Tools > Macros > Edit Macros (the IDE opens; run with F5).

Naming rules: a macro/module/library name must begin with a letter, contain no spaces, and no special characters except the underscore (_).

Macro as a Function

Instead of Sub … End Sub, use Function … End Function. A function accepts arguments, performs a calculation and returns a result — useful for repeated custom calculations (e.g. tiles needed for a floor). Call it in a cell like a built-in function.

Summary

  • A macro automates repeated tasks; recording must be enabled first.
  • Library > Module > Macro. Code: Sub … End Sub, written in BASIC.
  • Names: start with a letter, no spaces, only _ allowed as a special character.
  • A macro-as-function returns a value and can be used inside a cell.

Quick check: 3 MCQs (tap an option)

Q1. Macros in LibreOffice are written in the language:

Q2. A Library is a collection of:

Q3. Which action is NOT recorded by the macro recorder?

Macro क्या है?

Macro: एक single instruction जो instructions का एक set चलाता है — commands / keystrokes का recorded sequence जिसे किसी भी बार चलाकर बार-बार होने वाले काम automate किए जाते हैं।

Macro Enable और Record करना

  1. Enable: Tools > Options > LibreOffice > Advanced > Enable macro recording tick कीजिए (default off)।
  2. Tools > Macros > Record Macro.
  3. Record करने वाली actions कीजिए।
  4. Stop Recording पर click कीजिए।
  5. Basic Macros dialog में Library/Module चुनकर macro नाम देकर Save कीजिए।
जो actions record नहीं होतीं: windows खोलना; दूसरी window की actions; window switch करना; sheet contents से असंबंधित actions; mouse से किए selections (सिर्फ़ keyboard selections record होते हैं)। Recorder सिर्फ़ Calc और Writer में काम करता है।

Macro चलाना

Tools > Macros > Run Macro > Library और Module expand कीजिए > macro चुनिए > Run।

Library, Module और Macro

याद रखिए: Library = Modules का collection; Module = Macros का collection। Default macro Main है, Standard library, Module1 में save।

दो containers दिखते हैं: LibreOffice Macros (pre-recorded — मत बदलिए) और My Macros (user के लिखे/जोड़े macros)।

BASIC में लिखा Macro

Macros BASIC भाषा में लिखे जाते हैं। Code Sub <name> से शुरू और End Sub पर ख़त्म होता है। Edit: Tools > Macros > Edit Macros (IDE खुलता है; F5 से run)।

Naming rules: macro/module/library नाम letter से शुरू हो, कोई space नहीं, और underscore (_) के अलावा कोई special character नहीं।

Function के रूप में Macro

Sub … End Sub के बजाय Function … End Function इस्तेमाल कीजिए। Function arguments लेता है, गणना करता है और result लौटाता है — बार-बार होने वाली custom गणनाओं को उपयोगी (जैसे floor के लिए tiles)। इसे cell में built-in function की तरह call कीजिए।

सारांश

  • Macro बार-बार होने वाले काम automate करता है; पहले recording enable करनी होती है।
  • Library > Module > Macro। Code: Sub … End Sub, BASIC में।
  • Names: letter से शुरू, कोई space नहीं, सिर्फ़ _ special character allowed।
  • Function वाला macro value लौटाता है और cell में इस्तेमाल हो सकता है।

झटपट जाँच: 3 MCQs (option पर tap करें)

Q1. LibreOffice में macros किस भाषा में लिखे जाते हैं?

Q2. Library किसका संग्रह है?

Q3. Macro recorder कौन सी action record नहीं करता?

Frequently Asked Questions

What is a macro in LibreOffice?

A macro is a single instruction that runs a whole set of recorded commands or keystrokes. It automates repeated tasks so they can be run any number of times with one click.

In which applications does the macro recorder work?

The macro recorder works only in LibreOffice Calc and Writer. Actions like opening windows or mouse selections are not recorded.

What is the relationship between a library, a module and a macro?

A library is a collection of modules, and a module is a collection of macros. The default macro Main is stored in the Standard library, Module1.

What are the naming rules for a macro?

A macro name must begin with a letter, must not contain spaces, and cannot use special characters except the underscore (_).

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free