Basic Macro of a workbook to call macro of another workbook

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
diraniyoussef
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am

Basic Macro of a workbook to call macro of another workbook

Post 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!)
LibreOffice 5.1.3.2 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
diraniyoussef
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am

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

Post 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?
LibreOffice 5.1.3.2 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11345
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31265
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

Call a global macro with the respective document as argument.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
diraniyoussef
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am

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

Post 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.
LibreOffice 5.1.3.2 on Windows 10
Post Reply