Skip to content

How to Fix LibreOffice Macro Error (Basic or Python Script Not Running)

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix LibreOffice Macro Error (Basic or Python Script Not Running). We cover key concepts, practical examples, and best practices.

LibreOffice supports macros written in Basic (StarBasic) and Python. When a macro does not run, the script location is wrong, the macro security level blocks it, or the Python runtime is not configured correctly for LibreOffice.

The Problem

You write or download a macro for Calc, Writer, or Impress. When you run it (Tools > Macros > Run Macros), nothing happens, or you see "BASIC syntax error" or "Python script not found."

Wrong approach — rewriting the macro from scratch.

The Fix

Check the macro security level:

1. Tools → Options → LibreOffice → Security
2. Click "Macro Security"
3. Set to "Medium" — prompts before running unsigned macros
4. Or set to "Low" for development (revert after testing)

For Basic macros, verify the module location:

1. Tools → Macros → Organize Macros → LibreOffice Basic
2. Expand My Macros or the document name
3. Ensure the module and macro name are visible
4. If not, create a new module and paste the code

For Python macros, check the Python path:

1. Tools → Options → LibreOffice → Advanced
2. Ensure "Enable macro recording" and "Enable Python scripting" are checked
3. Python scripts go in ~/.config/libreoffice/4/user/Scripts/python/
4. Restart LibreOffice after adding Python files

Expected output:

Macro executes successfully
Desired action is performed in the document
No error messages in the macro editor or console

Prevention Tips

  • Store reusable macros in "My Macros" (global) rather than in individual documents
  • Use "Medium" macro security during development, "High" for production use
  • Test Python macros from the terminal first: python3 your_script.py
  • Organize related macros into named modules for easier management
  • Sign your macros with a certificate for trusted execution across the organization

Common Mistakes with macro error

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world LIBREOFFICE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my Python macro run in the terminal but not in LibreOffice?

LibreOffice uses its own Python environment, not the system Python. Libraries installed via pip may not be available. Use python3 -m pip install --user pyuno to install packages for LibreOffice's Python, or embed the library code in your macro.

How do I debug a LibreOffice Basic macro?

Use the built-in debugger: Tools > Macros > Organize Macros > LibreOffice Basic. Select the macro and click "Edit." Use F8 to step through lines, F5 to run, and set breakpoints by clicking in the left margin. The watch window shows variable values.

Can I run a macro automatically when a document opens?

Yes, name your macro OnLoad or use the document event "Open Document" in Tools > Customize > Events. Assign the macro to the "Open Document" event. The macro runs automatically when anyone opens the document.

Related: DodaTech's Macro Compatibility Scanner reviews Basic and Python macros for version compatibility, library dependencies, and security risks before deployment. Use with DodaZIP for macro backup.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro