Ask Your Question

Can Libreoffice basic macros listen loading a file? [closed]

asked 2016-11-23 19:19:59 +0100

gulsah gravatar image

updated 2020-07-21 05:58:25 +0100

Alex Kemp gravatar image

I am trying to write a basic macro (After i'll convert it an extension) for writer which listens exist file's loading/opening. While i read Andrew Pitonyak's book about macros i've learned about Listeners. But there is no listener for service. I want to see a dialog box when any document loaded /opened to writer. Is it possible? If yes could anyone help me to find a document about it?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-07-21 05:59:33.038843

2 Answers

Sort by » oldest newest most voted

answered 2016-11-24 03:46:40 +0100

karolus gravatar image


sub example
    msgbox( thisComponent.Title )
end sub

adopt the code to your needs, store it into ……MyMakros→Standard→…

and bind it to →Tools→Customize→Events→→Open Document (choose LibreOffice in the Optionbox below )

edit flag offensive delete link more


@karolus - simple but effective - Very Nice!

Ratslinger gravatar imageRatslinger ( 2016-11-24 04:26:52 +0100 )edit

we need first to check if we just open writer:

sub example
doc = thisComponent
if doc.Identifier = "" then
    msgbox( doc.Title )
end if
end sub
karolus gravatar imagekarolus ( 2016-11-24 05:10:25 +0100 )edit

Hey \o/ Thanks for that simple and handy solution. It works for open a file while libreoffice running. But when i double click an odt document when libreoffce is off i see "Basic Runtime Error: Property or method not found:Identifier". I think that cause of ThisComponent What can i use instead of ThisComponent to specify writer component?

gulsah gravatar imagegulsah ( 2016-11-24 09:36:46 +0100 )edit

I cannot reproduce the Issue, it works for me also with completely closed LO and double clicking some LO-file.
to restrict your code running only on writer-docs see the example in my last comment above yours.

karolus gravatar imagekarolus ( 2016-11-24 15:28:43 +0100 )edit

That error was cause of my fault. I works now correctly. Thanks.

gulsah gravatar imagegulsah ( 2016-11-25 10:21:06 +0100 )edit

answered 2016-11-23 23:13:24 +0100

Ratslinger gravatar image

Actually the basic information you need is in Pitonyak's OOME book. I have only created one listener (see this link - click here ) and it appears you need to do the same.

Running the code from the link mentioned produced:

image description

Based upon that you would have three routines to set up - StartHandler, StopHandler, and loadComponentFromURL. This last routine is where you would determine the type of document being opened (Writer, Calc, Base etc.) and if it's the one you want (Writer in your case) display your Dialog.

Only having done this once, can't be too much help but this may give you a start.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-11-23 19:19:59 +0100

Seen: 381 times

Last updated: Nov 24 '16