Basic Macro of a workbook to call macro of another workbook

Keyboard macros or custom scripts

Basic Macro of a workbook to call macro of another workbook

Postby diraniyoussef » Fri Jun 17, 2016 3:38 pm

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
diraniyoussef
 
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am

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

Postby Zizi64 » Fri Jun 17, 2016 5:18 pm

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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 6982
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby diraniyoussef » Fri Jun 17, 2016 11:20 pm

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
diraniyoussef
 
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am

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

Postby Zizi64 » Sat Jun 18, 2016 10:09 am

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; LO4.4.7, LO5.4.7 on Win7x64Prof.
PortableApps, winPenPack: LO3.3.0-LO6.1.0 and AOO4.1.5
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
Zizi64
Volunteer
 
Posts: 6982
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby Villeroy » Sat Jun 18, 2016 10:45 am

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25556
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby diraniyoussef » Sun Jun 19, 2016 10:02 am

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
diraniyoussef
 
Posts: 7
Joined: Fri Jun 17, 2016 4:57 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 5 guests