| View previous topic :: View next topic |
| Author |
Message |
williamamdm Guest
|
Posted: Thu Feb 05, 2004 12:54 am Post subject: apply macro from differents files |
|
|
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  |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Feb 05, 2004 9:18 am Post subject: |
|
|
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 |
|
 |
williamamdm Guest
|
Posted: Mon Feb 09, 2004 12:46 am Post subject: |
|
|
Tks a lot, your script is wonderful and now my script run very well  |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon Mar 15, 2004 8:27 am Post subject: |
|
|
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 |
|
 |
Grooveman General User

Joined: 17 Feb 2004 Posts: 14
|
Posted: Tue Apr 06, 2004 1:45 am Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Wed Jul 14, 2004 8:20 pm Post subject: |
|
|
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(' ') |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Wed Jul 14, 2004 10:50 pm Post subject: |
|
|
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 |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Jul 15, 2004 6:42 am Post subject: |
|
|
| 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 |
|
 |
BHARATHY Power User

Joined: 27 Apr 2006 Posts: 56 Location: bangalore
|
Posted: Thu Jun 15, 2006 2:04 am Post subject: |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Fri Jun 16, 2006 11:30 am Post subject: |
|
|
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 |
|
 |
BHARATHY Power User

Joined: 27 Apr 2006 Posts: 56 Location: bangalore
|
Posted: Sun Jun 18, 2006 8:52 pm Post subject: |
|
|
| Hi thanks a lot for the reply. |
|
| Back to top |
|
 |
|