OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

apply macro from differents files

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
williamamdm
Guest





PostPosted: Thu Feb 05, 2004 12:54 am    Post subject: apply macro from differents files Reply with quote

Hello, sorry from my english but i'm french.

I'm using OO 1.0.1 and I've some probleme. I've two Open office files opened and I want used macro ( called macro1()) in a file which is define in the other file.
I've tried to use the simple "call macro1()" but I've an error that this macro is not defined.
Do you know the syntax to call a macro from an other open office file open.

Tks a lot
William Very Happy
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Feb 05, 2004 7:57 am    Post subject: Reply with quote

You can execute a macro via. a properly formed URL.

There is at least one example burried in the links below that shows how to call such a URL from Basic. (2nd example I believe)

I also know for sure that it is possible to call a macro in a document by putting the document name as part of the URL, if formed properly.

Sorry, at the moment, I've got to run and can't give you a better answer.


http://www.oooforum.org/forum/viewtopic.php?t=4071
http://www.oooforum.org/forum/viewtopic.php?p=15589#15589
http://www.oooforum.org/forum/viewtopic.php?p=9861#9861
http://www.oooforum.org/forum/viewtopic.php?p=17377#17377
http://www.oooforum.org/forum/viewtopic.php?t=3196
http://www.oooforum.org/forum/viewtopic.php?t=2619
http://www.oooforum.org/forum/viewtopic.php?p=11794#11794

http://www.oooforum.org/forum/viewtopic.php?p=13053#13053

http://www.oooforum.org/forum/viewtopic.php?t=4285

http://www.oooforum.org/forum/viewtopic.php?t=3772

http://www.oooforum.org/forum/viewtopic.php?t=4163

http://www.oooforum.org/forum/viewtopic.php?t=2688
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Feb 05, 2004 9:18 am    Post subject: Reply with quote

Here is a more detailed reply.

I create two documents. Since I have not saved them, they are named Untitled1 and Untitled2.

(FYI...Untitled1 is a drawing, Untitled2 is a spreadsheet, but this is irrelevant.)

In the macros of Untitled2 I put this....
Code:
Sub SaySomething( x )
   MsgBox x
End Sub

It is important that this code is in Module1 of the Standard library of Untitled2.

In the macros of Untitled1, I put this...
Code:
Sub Main
   cMacroUrlString = "macro://Untitled2/Standard.Module1.SaySomething(Hi)"
'   cMacroUrlString = ".uno:About"
   
   oURL = createUnoStruct( "com.sun.star.util.URL" )
   oURL.Complete = cMacroUrlString
     
   oUrlParser = createUnoService( "com.sun.star.util.URLTransformer" )
   
   oUrlParser.parseStrict( oURL )
   
   oFrame = StarDesktop.getCurrentFrame()
   
   oDispatcher = oFrame.queryDispatch( oURL, "_self", 0 )
   oDispatcher.dispatch( oURL, Array() )
End Sub


When I execute the macro in Untitled1, it calls the macro in Untitled2.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
williamamdm
Guest





PostPosted: Mon Feb 09, 2004 12:46 am    Post subject: Reply with quote

Tks a lot, your script is wonderful and now my script run very well Laughing
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Mar 15, 2004 8:27 am    Post subject: Reply with quote

See above where I wrote....
Code:
.......
.......
.......
   oFrame = StarDesktop.getCurrentFrame()
   
   oDispatcher = oFrame.queryDispatch( oURL, "_self", 0 )
   oDispatcher.dispatch( oURL, Array() )

It is probably not necessary to use oFrame = StarDesktop.getCurrentFrame(). The dispatch of the URL to call the macro can be dispatched on any frame, including StarDesktop itself.

I just confirmed that the following works, directly dispatching on StarDesktop. Here is much shorter code....
Code:
Sub Main
   oDispatch = createUnoService( "com.sun.star.frame.DispatchHelper" )
   oDispatch.executeDispatch( StarDesktop, "macro://Untitled2/Standard.Module1.SaySomething(Hi)", "", 0, Array() )
End Sub

Now, if the Untitled2 document were saved as "test.sxw", then the following would still call the macro in it, by changing "Untitled2" to "test" (note lack of suffix!).
Code:
Sub Main
   oDispatch = createUnoService( "com.sun.star.frame.DispatchHelper" )
   oDispatch.executeDispatch( StarDesktop, "macro://test/Standard.Module1.SaySomething(Hi)", "", 0, Array() )
End Sub

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Grooveman
General User
General User


Joined: 17 Feb 2004
Posts: 14

PostPosted: Tue Apr 06, 2004 1:45 am    Post subject: Reply with quote

Hello,

I tried to make the urlparse function in Visual Basic but it gives an error to me at oUrlParser.parseStrict (oURL). the error is: Object doesnt support property or method. But the method exists in the API. what am i doing wrong?

Code:
Sub macro(dir As String)
   Dim cMacroUrlString As String
   Dim oURL As Object
   Dim oUrlParser As Object
   
   cMacroUrlString = "macro://Untitled1/Standard.Module1.createDS(" + dir + ")"
   
   Set oURL = createStruct("com.sun.star.util.URL")
   oURL.complete = cMacroUrlString
     
   Set oUrlParser = objServiceManager.createInstance("com.sun.star.util.URLTransformer")
   
   oUrlParser.parseStrict (oURL)
 
   Call dispatcher.dispatch(oURL, noArgs())

End Sub
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jul 14, 2004 8:20 pm    Post subject: Reply with quote

Its a good article and usetoful developers .
I really excited abt this and gone through few examples.But we need still clear explanation with
examples.


Krishna

Software Engg

Srishti Software Bangalore javascript:emoticon('Very Happy')
Back to top
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Jul 14, 2004 10:50 pm    Post subject: Reply with quote

Grooveman I guess it's because the object is not mapped correctly to a UNO struct.
You think that a VB struct created by createStruct() is the same as the createUnoStruct() RTL Starbasic function, but it's not.
You have to use the CoreReflection service to create a reflection of a UNO object.

In general calling a function that is contained in a document's librarycontainer from another document's macro should be possible without the UNO dispatcher by loading the needed library from the other document's libarycontainer.
Somehow it didn't work for me, so I cannot provide code yet.

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Jul 15, 2004 6:42 am    Post subject: Reply with quote

Cybb20 wrote:
In general calling a function that is contained in a document's librarycontainer from another document's macro should be possible without the UNO dispatcher by loading the needed library from the other document's libarycontainer.
Somehow it didn't work for me, so I cannot provide code yet.


Other than the ugly dispatcher/url approach, I'm not sure if you can call a macro, as a function, that is in a document's library. I wish you could. I think API support for this should be added. (Maybe someone needs to ask for it?)

I believe that the ability to do this is what is being asked for over in this thread...
http://www.oooforum.org/forum/viewtopic.php?t=10821
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
BHARATHY
Power User
Power User


Joined: 27 Apr 2006
Posts: 56
Location: bangalore

PostPosted: Thu Jun 15, 2006 2:04 am    Post subject: Reply with quote

Hi i want to know how a macro in Untitled1 can call the macro in test.sxw after i close test.sxw. i tried to call macro in test.sxw from untitled1 using the following code. but it does not work when test.sxw is closed. the macro in test.sxw gets called only if "test.sxw" is open.

Sub Main
oDispatch = createUnoService( "com.sun.star.frame.DispatchHelper" )
oDispatch.executeDispatch( StarDesktop, "macro://test/Standard.Module1.SaySomething(Hi)", "", 0, Array() )
End Sub

thank you
Back to top
View user's profile Send private message Yahoo Messenger
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Jun 16, 2006 11:30 am    Post subject: Reply with quote

The document must be open. It might also be true that the library containing the macro may have to be loaded (I havenot verified this).
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
BHARATHY
Power User
Power User


Joined: 27 Apr 2006
Posts: 56
Location: bangalore

PostPosted: Sun Jun 18, 2006 8:52 pm    Post subject: Reply with quote

Hi thanks a lot for the reply.
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group