Hi,
Do you know if in Libreoffice Calc 6 it’s possible to run from terminal an existing macro in a specific cell?
I’m using Linux Ubuntu 16.04.
Thanks
Hi,
Do you know if in Libreoffice Calc 6 it’s possible to run from terminal an existing macro in a specific cell?
I’m using Linux Ubuntu 16.04.
Thanks
How do you “run a macro in a cell”?
Please give more details. Does the cell have a user-defined function perhaps? What have you tried so far? See guidelines for asking.
Normally I select a cell with mouse and run this macro by clicking a button.
Do you want to command:
-1- Open the file (invisible?)
-2- select a specific cell (or put the focus on it) ??
-3- run the macro (contained in the document or in your general library?)
-4- returm to the original selection? save the file? close the file?
Hello,
Executing macros from a terminal is not based upon the module the macro is associated with but rather where the actual macro resides. It must be in the Standard library of My Macros. Subs work without or without parameters but it seems Functions will not (unless I am missing something).
A sample of one is in my answer on this post → Base: Page header/footer not generated .
Also, this simple Sub:
Sub FindSheet(aNumber)
MsgBox "Here is the number " & aNumber
End Sub
run from terminal as:
libreoffice6.0 "macro:///Standard.Module1.FindSheet(4)"
or on some systems:
soffice "macro:///Standard.Module1.FindSheet(4)"
displays the proper variable and message in a message box.
Another note, when executing the macro from terminal and all of LO is closed, you will briefly see the LO splash screen displayed.
If you are looking to interact with Calc from a terminal, see this post → click here. It is mostly for Python but shows how to directly access an open Calc document from a terminal.
If this answers your question please tick the (upper left area of answer). It helps others to know there was an accepted answer.
" It must be in the Standard library of My Macros." Not true. This works for macros embedded in the document (syntax is powershell on Windows): & "C:\Program Files (x86)\LibreOffice 5\program\soffice.exe" "vnd.sun.star.script:Standard.Module1.FindSheet?language=Basic&location=document" "Untitled 1.odt"
. However if parameters are needed, they must be parsed from the URL.
I run this by terminal:
soffice “vnd.sun.star.script:Standard.Module1.Ora?language=Basic&location=application” “/home/lim/Scrivania/Test.ods” where Ora is my macro and Test.ods a spreadsheet where I want to run it.
It works but:
I don’t know how to run macro in a specific cell.
Modify the macro to accept parameters for row and column.
Sub Ora(nColumn As Long, nRow As Long)
cell = sheet.getCellByPosition(nColumn, nRow)
Call it like this.
soffice "macro:///Standard.Module1.Ora(2,3)" "/home/lim/Scrivania/Test.ods"
The spreadsheet must be closed to work and I need to maintain it ever opened.
Then that is not the right approach. Instead, start LibreOffice in listening mode and execute API commands from outside.
IMHO, the easiest way to do this is with Python. A popular tutorial that shows everything you need is at Interface-oriented programming in OpenOffice / LibreOffice : automate your office tasks with Python Macros.
(Just noticed that this is the same link @Ratslinger included. Great minds think alike, apparently.)
Ok, I try.
Thank you