[Solved] Macro to insert an OLE object

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
fmolina
Posts: 4
Joined: Fri Jan 16, 2009 10:15 pm

[Solved] Macro to insert an OLE object

Post by fmolina »

Hi all:

This may be a silly question, but I could not find the answer, so please forgive me. I am using OOo 3.0 on windows XP SP3.

I want to write a macro to insert a new OLE object into a Writer document and start the server. More specifically, I want to insert a new MathType equation, thus openieng the OLE server. How to do that? I tried to record a macro but it only opens the dialog.

Thank you in advance.

Fer
Last edited by fmolina on Tue Jan 20, 2009 9:05 pm, edited 1 time in total.
OOo 3.0.X on Ms Windows XP + fedora linux/solaris (to be)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to insert an OLE object

Post by Villeroy »

Search the ol' forum's "Code Snippets" forum for "OLE". http://www.oooforum.org/forum/search.phtml
One of the results: http://www.oooforum.org/forum/viewtopic ... hlight=ole
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
fmolina
Posts: 4
Joined: Fri Jan 16, 2009 10:15 pm

Re: Macro to insert an OLE object

Post by fmolina »

Thanks Villeroy, I found code but , seems to not be working in 3.0.
Specifically, I found this: http://www.oooforum.org/forum/viewtopic ... hlight=ole
(first example) but it does not work well: It opens OOo Math but then starts an endless chain of beeps and does not respond anymore. I must kill OOo Writer to stop.
¿Someone has any further advice?
Regards
OOo 3.0.X on Ms Windows XP + fedora linux/solaris (to be)
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Re: Macro to insert an OLE object

Post by ms777 »

fmolina wrote:...Specifically, I found this: http://www.oooforum.org/forum/viewtopic ... hlight=ole
(first example) but it does not work well: It opens OOo Math but then starts an endless chain of beeps and does not respond anymore. I must kill OOo Writer to stop....
Ooops - I will check that in two weeks when I am back at my computer. I am still at OO 2.4

To insert OO objects into writer, I would recommend an easier way:
1.) create an ole2shape by the document's createInstance method
2.) insert it into drawpage
3.) set the CLSID to the math formula CLSID. You can get that by xraying a doc with an formula inserted
see http://www.oooforum.org/forum/viewtopic.phtml?t=61104 as a java example

For then activating / modifying the inserted formula see http://www.oooforum.org/forum/viewtopic.phtml?t=78793

Good luck,

ms777
fmolina
Posts: 4
Joined: Fri Jan 16, 2009 10:15 pm

Re: Macro to insert an OLE object

Post by fmolina »

Thanks, ms777, I will chek that and tell what happened

Regards
OOo 3.0.X on Ms Windows XP + fedora linux/solaris (to be)
fmolina
Posts: 4
Joined: Fri Jan 16, 2009 10:15 pm

Re: Macro to insert an OLE object

Post by fmolina »

OK, it worked, borrowing some code from Andrew Pitonyak's macro guide. The code to insert a MathType 6 equation is

Code: Select all

sub InsertMathTypeEcuation
rem ----------------------------------------------------------------------
rem define variables
dim obj   as object
dim SName as string
dim oXEO  as object
rem ----------------------------------------------------------------------
SName = "com.sun.star.text.TextEmbeddedObject"
obj = ThisComponent.createInstance(sName)
obj.CLSID = "0002CE03-0000-0000-C000-000000000046"
obj.attach(ThisComponent.currentController().Selection.getByIndex(0))
oXEO = obj.ExtendedControlOverEmbeddedObject
oXEO.doVerb(0)

end sub
By the way, I tried a bit to do the same with OOo Math but without success. Not a big deal, because there is a button to do that.

Regards,

Fernando
OOo 3.0.X on Ms Windows XP + fedora linux/solaris (to be)
SanchoPanza
Posts: 5
Joined: Tue Mar 21, 2017 7:46 am

Re: [Solved] Macro to insert an OLE object

Post by SanchoPanza »

Given links are not working. I want to insert a ole object from a specified path by using macro. I tried to record a macro to reach dispatchers but it didn't help me. Also I couldn't find any solution to my problem. Is there any way to do it? Thanks.
OpenOffice 4.1.3 on Windows 10
Post Reply