Macro guide

LibreOffice macros on Windows — run, write & fix macro guide

LibreOffice macros on Windows automate repetitive tasks in Writer, Calc and Impress. LibreOffice uses LibreOffice Basic (similar to VBA), Python and JavaScript. Access the macro editor via Tools → Macros → Edit Macros.

Run macros in LibreOffice on Windows

  • 1

    Open the macro dialog

    Tools → MacrosRun Macro. The macro selector opens.

  • 2

    Select your macro

    Browse to your macro in the library tree. Select it and click Run.

Create a macro in LibreOffice Basic

LibreOffice Basic — Tools > Macros > Edit Macros
' Simple macro example — inserts text in Writer:
Sub InsertText()
Dim oDoc As Object
Dim oText As Object
Dim oCursor As Object
oDoc = ThisComponent
oText = oDoc.getText()
oCursor = oText.createTextCursor()
oText.insertString(oCursor, "Hello from LibreOffice Basic!", False)
End Sub

Macro security settings on Windows

By default LibreOffice blocks unsigned macros. To allow macros:

  • Tools → Options → LibreOffice → Security → Macro Security
  • Set to Medium to ask before running each macro
  • Or add trusted file locations: Security → Trusted Sources → File Locations
Do not set macro security to Low. Always verify macros from unknown sources before running them.

Macro questions

Do Excel VBA macros work in LibreOffice?

Partially. Simple VBA macros often work because LibreOffice Basic is similar to VBA. Complex macros using Excel-specific objects (Workbook, Application, ActiveX) need rewriting. LibreOffice has a VBA compatibility mode (Tools → Options → LibreOffice Basic → VBA Properties) that improves compatibility for basic VBA code.

LibreOffice macros not running on Windows

Check macro security: Tools → Options → Security → Macro Security. If set to Very High, all macros are blocked. Set to Medium to allow macros with a confirmation prompt. Also check if the file is in a trusted location.

Need extensions instead?

Add functionality with LibreOffice extensions.

Extensions guide