Ask Your Question
0

Execute macro in Calc from terminal

asked 2018-03-26 12:57:13 +0200

DavideTN gravatar image

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 flag offensive close merge delete

Comments

1

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

Lupp gravatar imageLupp ( 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.

Jim K gravatar imageJim K ( 2018-03-26 20:04:35 +0200 )edit

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

DavideTN gravatar imageDavideTN ( 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?

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

2 Answers

Sort by » oldest newest most voted
0

answered 2018-03-27 19:32:52 +0200

Jim K gravatar image

updated 2018-03-27 19:37:23 +0200

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

edit flag offensive delete link more

Comments

Ok, I try. Thank you

DavideTN gravatar imageDavideTN ( 2018-03-28 08:50:46 +0200 )edit
0

answered 2018-03-26 17:36:37 +0200

Ratslinger gravatar image

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.

edit flag offensive delete link more

Comments

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

Jim K gravatar imageJim K ( 2018-03-26 20:31:51 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 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

DavideTN gravatar imageDavideTN ( 2018-03-27 07:58:01 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-26 12:57:13 +0200

Seen: 825 times

Last updated: Mar 27 '18