I have two doc LibreOffice calc test1.ods and test2.ods. I want run a script in test2 from the script of test1.
REM ***** BASIC *****
'Script on Test1
Sub Main
Dim urlDest As String
Dim PropFich(1) As New com.sun.star.beans.PropertyValue
Dim oDocDest As Object
PropFich(0).Name = "MacroExecutionMode"
PropFich(0).value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
urlDest = ConvertToUrl("/home/patrick/Bureau/Test/test2.ods")
oDocDest = StarDesktop.loadComponentFromUrl(urlDest, "_blank", 0, PropFich())
' ...
'run oDocDest.Standard.Module1.Main() ???
End Sub
Get the script provider of the other document and use it to invoke the macro.
oScriptProvider = oDocDest.getScriptProvider()
oScript = oScriptProvider.getScript(_
"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document")
result = oScript.invoke(Array(), Array(), Array())
For this to work, you need to allow macros to run by going to Tools > Options > Security.