Page 1 of 1

Basic Macro of a workbook to call macro of another workbook

Posted: Fri Jun 17, 2016 3:38 pm
by diraniyoussef
One Basic macro of the Standard library of an embedded Calc document should call a particular macro of the embedded Standard library of another wokbook.
Both workbooks are open.
e.g.
In the Standard library of a workbook named "WKB 1.ods", inside Module1, a macro called macro1 as
sub macro1
'here should be the call to macro2

end sub

and in "WKB 2.ods", inside Module1, resides a macro called macro2
sub macro2
'doing some stuff relevant to workbook 2
end sub

If the 2 macros belonged to the same workbook then I would had stated the module name e.g. Module1.macro2 (or Module2.macro2 if macro2 is inside a separate module).
I guess the Standard library of both workbooks are loaded so no need to use
BasicLibraries.loadLibrary("something pointing to the Standard of the second workbook")
It has to be then like Standard.Module1.macro2 but referring to the desired Standard.
(By the way, even if macro2 was in the same workbook Standard, Standard.Module1.macro2 doesn't work and I don't know why!)

Re: Basic Macro of a workbook to call macro of another workb

Posted: Fri Jun 17, 2016 5:18 pm
by Zizi64
Store your macros into MyMacros, and get the documents (what you want to modify by the macros) with the
oDoc1 = LOADFROMURL(.....)
oDoc2 = LOADFROMURL(.....)
function. Then you can modify the properties and contents of the sheets, cells of both documents.

Re: Basic Macro of a workbook to call macro of another workb

Posted: Fri Jun 17, 2016 11:20 pm
by diraniyoussef
I want to let workbook 2 perform a macro, and this order must take place in macro1.
The flow control is always in macro1. How to perform that?

Re: Basic Macro of a workbook to call macro of another workb

Posted: Sat Jun 18, 2016 10:09 am
by Zizi64
You can call a macro what is stored in
- the actual document (where the macros called from)
- the MyMacros.

If I know it exactly: you can not call a macro stored in an another document.

Re: Basic Macro of a workbook to call macro of another workb

Posted: Sat Jun 18, 2016 10:45 am
by Villeroy
Call a global macro with the respective document as argument.

Re: Basic Macro of a workbook to call macro of another workb

Posted: Sun Jun 19, 2016 10:02 am
by diraniyoussef
That gives me a hint, Villeroy.
I could even stick on with the macro of workbook 1 and control workbook 2 directly (without using a global macro). I will show how for the sake of public benefit (since I searched for this particular thread and didn't find results)
'I created workbook 2 and loaded it
oDocument = StarDesktop.LoadComponentFromURL( fnURL, "_blank", 0, PV) 'fnURL is a variable and PV is an array of UNO structs
'Then I controlled workbook 2 COMPONENT (oDocument) directly
oDocument.Sheets(0).getcellbyposition(6,6).string = "156"
'and that's it

As for having a way like in Excel VBA's
Application.Run "MacroBook!MacroName"
I suggest to write a global macro that does this, the way to write it can be inspired from Andrew Pitonyak's book "OpenOffice.org Macros Explained" OOME Third Edition, "Listing 227. Inspect each open component." example.