How to raise a event for document before close of libre writer?

In word the below event is available to raise event for before document close. Like that can any one please help me how to raise a event for before document close of libre writer from VB.NET?

Private Sub oWord_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As Boolean)

Cancel = True

End Sub

Should be combined with How to cancel the writer document close from VB.NET?. Basically a duplicate.

LO has various document events including “Document is going to be closed”. To access these events click Tools > Customise and select the Events Tab. Click on the event and Assign: Macro. Write the Macro before you do this. It is better to create your Macro in a Module in the document. Attached is a document using the document before close event to show a message box.
DocCloMac.odt

Thanks for the solution.

But i would like raise the event ‘DocumentBeforeClose’ in VB.NET while closing the libreoffice writer. Also during the libre document close i will validate some case if the case is not success then the libre document will not close. can you please help me how to raise the event while document close and cancel the event if the validate fails?

Use XCloseListener to be notified when the document gets closed. To stop the document from closing, throw a CloseVetoException from the queryClosing method.

There is some related Basic code at [Solved] Intercept onClose event of database doc? (in Basic) (View topic) • Apache OpenOffice Community Forum.

EDIT:

Sorry, but what you want is impossible. The code you posted is correct. Throwing CloseVetoException will prevent the outer frame from closing if you call addCloseListener on the frame.

frame = xComponent.getCurrentController().getFrame()
frame.addCloseListener(myListener)

But the inner frame containing the document can still be closed, as explained at http://openoffice.2283327.n4.nabble.com/api-dev-prevent-document-closing-td2767642.html. Listening to the inner frame (xComponent) will still result in the method being called, but in that case, CloseVetoException has no effect.

It sounds like a different approach is needed instead, such as a button that says “Validate document”.

A similar question was asked at [Solved] Cancel event, [Impossible] Cancel close document (View topic) • Apache OpenOffice Community Forum.

Thanks for the solution.

I tried the below code and i could not stop the document from closing. please correct me the below is correct?

    Public Sub queryClosing(ByVal oSource As unoidl.com.sun.star.lang.EventObject, ByVal bGetsOwnership As Boolean) Implements XCloseListener.queryClosing
        Dim bRetval = MsgBox("Do you want to close?", vbYesNo)
        If bRetval = vbNo Then
            Throw New CloseVetoException()
        End If
    End Sub