Syntax for opening a macro with another macro

I have tried to RTFM, but I am stumped for the correct syntax to run a macro that exists in one ODS file from a macro that is being run in another ODS file.

Context:
FILE1.ODS and FILE2.ODS are both open.
FILE1 is running MacroOne, and from it I want to call a macro that exists in FILE2, MacroTwo so that it operates on FILE2.
MacroTwo exists in FILE2 in the file’s Standard folder, Module1, Sub MacroTwo (Standard.Module1.MacroTwo)

Can anyone tell me the proper syntax or command sequence to accomplish this?
Thank you in advance.

IMHO that is not possible, but you can place your macros in your library in your profile. This macros can see each other and called from different files.
.
It is possible to open a file and execute a macro directly via command-line, but it is executed in the second file, without access to the first.

Let’s try.
To FILE1.ODS:

Sub MacroOne
  Dim oDoc2 As Object, oScript As Object
  
  oDoc2=Doc_FindByTitle("FILE2.ODS")  
  oScript=oDoc2.ScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.MacroTwo?language=Basic&location=document")
  oScript.invoke Array("Hello from MacroOne"), Array(), Array()
End Sub

Function Doc_FindByTitle(Byval Title As String) As Object
  Dim oComp As Object
  For Each oComp In StarDesktop.Components
    If LCase(oComp.Title)=LCase(Title) Then
      Doc_FindByTitle = oComp
      Exit Function
    End If
  Next oComp
End Function

To FILE2.ODS, Standard.Module1:

Sub MacroTwo(ByVal arg)
  Msgbox arg
End Sub
4 Likes

How did your trial turn out?

Using my standard profile the .Title property shows a lot of additional information. Example:


If I need to identify a second component, I would need to go a different way.

Wolfgang, this example is not for you. :slightly_smiling_face:

Thank you @sokol92, this works very well.

Can you suggest whether this function could be shortened if I already have the full path to FILE2 stored in a string variable (F2PATH) ?

As usual

	GlobalScope.BasicLibraries.LoadLibrary("Tools")
	oDoc2 = OpenDocument(ConvertToURL(F2PATH), Array())
1 Like