LibreOffice Calc allows users to create their own macros using the built-in programming language StarBasic. This language is very similar to VBA , however, has limited functionality because it is rarely used.
Modern programming languages, such as Python, provide much more possibilities and have a wider range of additional libraries for all occasions.
So, let's learn how you can create your own macros using such a popular programming language as Python.
First, let's remember how you can write your own program using the standard LibreOffice Calc tools for writing macros.
Below is the code for the macro
To add a new macro, open the menu
Sub HelloWorld GlobalScope.BasicLibraries.loadLibrary("ScriptForge") 'REM "doc" it's a current LO Calc workbook (active worksheet) doc = CreateScriptService("Calc") doc.SetValue("B7", "Hello World!") End Sub
Then, close Macro Editor, return to LibreOffice Calc and run our new macro via the menu
Before writing a macro on Python, we need to first create a *.py file (
%APPDATA%\LibreOffice\4\user\scripts\python
If folders scripts and python are missing, you need to create them manually.
Below is the Python script for the macro
To add a new macro, open the file
from scriptforge import CreateScriptService
def HelloPython():
doc = CreateScriptService("Calc")
doc.SetValue("B8", "Hello Python!")
return None
Then, close
You can also use a ready-made set functions and utility written on
After that, this functionality will be available in all files that are opened in LibreOffice Calc.