# Execute macro in Calc from terminal

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

edit retag close merge delete

1

How do you "run a macro in a cell"?

( 2018-03-26 13:37:31 +0200 )edit

Please give more details. Does the cell have a user-defined function perhaps? What have you tried so far? See guidelines for asking.

( 2018-03-26 20:04:35 +0200 )edit

Normally I select a cell with mouse and run this macro by clicking a button.

( 2018-03-27 07:15:57 +0200 )edit

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?

( 2018-03-27 11:05:28 +0200 )edit

Sort by » oldest newest most voted

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 http://christopher5106.github.io/offi....

(Just noticed that this is the same link @Ratslinger included. Great minds think alike, apparently.)

more

Ok, I try. Thank you

( 2018-03-28 08:50:46 +0200 )edit

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.

more

" 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.

( 2018-03-26 20:31:51 +0200 )edit

@Jim K Thanks for comment. Had to use full path for document not just the name.

( 2018-03-26 20:58:36 +0200 )edit

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:

1) I don't know how to run macro in a specific cell; 2) The spreadsheet must be closed to work and I need to maintain it ever opened

( 2018-03-27 07:58:01 +0200 )edit