2

I have two doc LibreOffice calc test1.ods and test2.ods. I want run a script in test2 from the script of test1.

  1. When test2 is open by the script of test1, i can't run the script on test2 even from test2. How i can pass out the security for the test2 doc ?
  2. How i can run automaticly the scrip on test2 from the script on 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
patol
  • 136
  • 2
  • 10

1 Answers1

2

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.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thanks, I’m testing this tonight, but what’s the point of the Array(). Is there argument ? : invoke(Array(), Array(), Array() – patol Aug 30 '21 at 15:05
  • Your `Main()` routine does not require any arguments, so that is why the array is empty. – Jim K Aug 30 '21 at 16:32
  • Ok, if I had any arguments they MUST be in arrays? – patol Aug 30 '21 at 20:05
  • It works perfectly. With MacroExecMode.ALWAYS_EXECUTE the test2 script runs without changing the Options Security section – patol Aug 30 '21 at 21:18