Can Libreoffice basic macros listen loading a file?

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?


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 )

@karolus - simple but effective - Very Nice!

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

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?

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.

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

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.