Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The way to do this is to call a macro using the UNO construct getScript(sScriptURI) and then call the invoke method for the object. That is the easy part. The hard part is figuring out the sScriptURI, which is a universal location for the script. There is a paucity of documentation about what, exactly, this is.

By trial and error you may find that a sScriptURI for a Basic macro looks like this:


You can see the different elements. By further trial and error, you may find that a Python macro with a method of the same name (call_me) saved in the following location:


Is accessible as follows:


Thus, if I have the following Python macro at the above location saved as

def call_me(*args ):
    return "call me"

Then if I invoke the following in Basic, it will return to the Basic macro the value set forth in the Python macro ("call me"):

Dim a(0),b(0),c(0) As Variant
scpr = ThisComponent.getScriptProvider
scmod = scpr.getScript("$call_me?language=Python&location=user")

returnFromPython = scmod.invoke(a,b,c)
MsgBox returnFromPython

location=share also is a valid location, I think, depending on where, exactly, the script is saved. For documentation of what are the arrays a, b, c, see the API reference. To make your Python macro work, you may need to redefine those.

(if this answers your question, please accept the answer by clicking the check mark (image description) to the left)