[Solved] How to call another macro in a same document?

Creating a macro - Writing a Script - Using the API

[Solved] How to call another macro in a same document?

Postby JeremyLi » Thu Mar 14, 2013 5:38 am

Hi All,

How to call another macro in a same document? E.g. my file name is Test.odb. Under Test.odb, there are two libraries:test and Standard. Under "test" library, there is a module named "Module1'. I wrote some code under "Standard" library and want to call the function under "test" library. How to call the function under "Module1" module ?

Thanks
Attachments
1.png
1.png (13.77 KiB) Viewed 5855 times
Last edited by JeremyLi on Fri Mar 15, 2013 5:09 am, edited 1 time in total.
OS: Win7
Infact i use libreOffice 3.6
JeremyLi
 
Posts: 30
Joined: Fri Mar 01, 2013 4:28 am

Re: How to call another macro in a same document?

Postby RPG » Thu Mar 14, 2013 11:24 am

Hello

First your module must be loaded with loadlibrary then you can use:
call libname.modulename.subname

Loading the library must be done but you d'not need always all parts for calling but when you have the subname in two modules then you must make clear which sub you want.

Romke
LibreOffice 6.2.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2172
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: How to call another macro in a same document?

Postby JeremyLi » Thu Mar 14, 2013 1:55 pm

Hi. Thanks for you replying。 I tried below to call the "Test" sub under "Standard" library

GlobalScope.BasicLibraries.LoadLibrary("Standard")
call Standard.Module1.Test

But it prompt error message about "Object variable not set" . Can you tell me what's wrong?

Thanks
OS: Win7
Infact i use libreOffice 3.6
JeremyLi
 
Posts: 30
Joined: Fri Mar 01, 2013 4:28 am

Re: How to call another macro in a same document?

Postby RPG » Thu Mar 14, 2013 3:54 pm

Hello

Code: Select all   Expand viewCollapse view
thiscomponent.BasicLibraries.loadlibrary("Kaarten")

For libraries in document.

I do use a combination of this
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****


sub LoadComponentLibrarie(oCompoment,sLibName as string)
' oComponent kan zowel een document zijn als globalscope
oContainer=oCompoment.BasicLibraries
if  oContainer.hasbyname(sLibName)   then
   if not oContainer.islibraryloaded(sLibName) then
      ' Laad nu de library
      oContainer.loadlibrary(sLibName)
   end if
else msgbox sLibName & " Does not exist as libname" & chr(13) & "We stop"
   end
end if
end sub



sub LoadComponentLibraries(oComponent,sLibNames)
dim sLibName
for each sLibName in split(sLibnames)
   LoadComponentLibrarie(oComponent,sLibName)
next
end sub




' oud 6-09-2912

sub LoadLibrarie(sLibName as string)
dim oContainer
oContainer=globalscope.BasicLibraries
if  oContainer.hasbyname(sLibName)   then
   if not oContainer.islibraryloaded(sLibName) then
      ' Laad nu de library
      oContainer.loadlibrary(sLibName)
   end if
else msgbox sLibName & " Does not exist as libname" & chr(13) & "We stop"
   end
end if


Romke
LibreOffice 6.2.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2172
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: How to call another macro in a same document?

Postby B Marcelly » Thu Mar 14, 2013 4:23 pm

Hi,
JeremyLi wrote:my file name is Test.odb.
Under Test.odb, there are two libraries:test and Standard.
Under "test" library, there is a module named "Module1'.
I wrote some code under "Standard" library and want to call the function under "test" library. How to call the function under "Module1" module ?

I suppose you want to call a macro named alpha(), from another macro in Standard.
In your macro stored in Standard library:
Code: Select all   Expand viewCollapse view
BasicLibraries.LoadLibrary("test")
alpha()

You need to LoadLibrary only once (it remains loaded until the document is closed). But it does not harm if you do it several times.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: How to call another macro in a same document?

Postby JeremyLi » Fri Mar 15, 2013 5:05 am

Oh... B Marcelly Thank you very much. That's exactly what i need. In fact, i have implemented load the library. But i don't know i can call the function directly。

And I want to say thanks to you, RPG. Thanks for your detail explain.

Thanks all. I have solved this problem. :D
OS: Win7
Infact i use libreOffice 3.6
JeremyLi
 
Posts: 30
Joined: Fri Mar 01, 2013 4:28 am

Re: [Solved] How to call another macro in a same document?

Postby JeremyLi » Fri Mar 15, 2013 10:41 am

Hi,
I find "RPG" is right too. Once i said following:
call Standard.Module1.Test
But it prompt error message about "Object variable not set" . Can you tell me what's wrong?

It is true, when i call the method in Standard library with above method, it will have error. But we can call the method in Standard library directly. Just use "Test()" is ok .But Test() method should contain in Standard library. If the method is not in standard library, we can use following code to call it.
Code: Select all   Expand viewCollapse view
call libname.modulename.subname
Notice, all of above are in a same document.

Thanks
OS: Win7
Infact i use libreOffice 3.6
JeremyLi
 
Posts: 30
Joined: Fri Mar 01, 2013 4:28 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests