Contact

LibreOffice Calc · Formulas and analysis · Intermediate

Record and replay a document-owned macro in LibreOffice Calc

Record and replay a document-owned macro. A controlled example with expected outcomes, changed-input checks and recovery.

Documentary author review; no native application testing claimed · Editorial standards

Record a small Paste Special operation, store it in the current ODS document, and replay it only after restoring the same selection and clipboard prerequisites. A recorded macro automates commands; it does not automatically make them independent of document state.

Use an already-authorized macro environment

This exercise follows LibreOffice 25.2 Community Calc, English menu-bar desktop on Windows or Linux. It is documentation-based; no macro has been executed or natively tested for this article. Continue only in an environment where benign local macros and the recorder are already authorized and available. If Record Macro is unavailable or execution is blocked, stop rather than lower macro security, enable all macros or install anything.

Save RecordedMultiply.ods. Fill A1:C3 with rows 1/2/3, 4/5/6 and 7/8/9. Put 2 in E1. Keep a separate baseline copy, because repeated multiplication is destructive and is not idempotent: running twice multiplies twice.

The intended first result is rows 2/4/6, 8/10/12 and 14/16/18. The total of the original nine values is 45; after multiplying by 2 it should be 90.

Record only the operation

  1. Copy E1, which contains the multiplier 2.
  2. Select A1:C3.
  3. Choose Tools > Macros > Record Macro.
  4. Choose Edit > Paste Special > Paste Special.
  5. Select All in the Paste area and Multiply in Operations, then confirm.
  6. Verify the nine values and click Stop Recording.

The source guide uses this dispatcher-based Paste Special example. Keep the recorded action short. The recorder does not capture every application operation or every dialog setting reliably, so success on this fixture does not establish that a more complex recording is complete.

Save inside the document

In the macro-saving dialog, select the current document in Save Macro In, not My Macros or the application’s LibreOffice Macros container. Select its Standard library and create a new module if necessary. Name the module PracticeOps and the macro PasteMultiply, then save.

Document ownership matters. A macro stored in My Macros belongs to your user environment and may be missing when the ODS is opened elsewhere. The application-supplied library is not a place to modify this exercise. Check the container, library, module and macro name before leaving the dialog, then save the ODS.

Replay with explicit prerequisites

Restore A1:C3 to the original values 1 through 9 without deleting the macro. Copy E1 again and select exactly A1:C3. Use Tools > Macros > Run Macro, select the current document’s Standard library, PracticeOps module and PasteMultiply macro, and run it under your existing authorization.

Expect the same doubled block and total 90. A wrong selection or stale clipboard can produce a wrong result even though the recorded code is unchanged. Do not replay repeatedly hoping the result will correct itself.

For the changed-input test, restore the original block again, change E1 to 3, copy it and select A1:C3. Replay once. Expect rows 3/6/9, 12/15/18 and 21/24/27, totaling 135. This proves that the recorded operation uses the prepared multiplier rather than assuming the first clipboard value is permanent.

Save and recover without weakening security

Save and reopen the document only within the existing macro policy. Confirm the macro remains under this document’s Standard library. If execution is disabled, preserve the file and report the policy boundary; do not change security to complete a tutorial.

If a replay changes the wrong cells, stop, use immediate Undo where available, or return to the baseline copy. Verify all nine values rather than just the total. For a non-recorded alternative, Paste Special explains the underlying manual operation, while this exercise owns recording, document storage and controlled replay.

Official references