Ask Your Question

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

asked 2017-12-01 18:16:24 +0100

Muru gravatar image

updated 2017-12-02 15:06:03 +0100

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

edit retag flag offensive close merge delete


Should be combined with Basically a duplicate.

Jim K gravatar imageJim K ( 2017-12-03 02:03:42 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-12-02 11:30:17 +0100

peterwt gravatar image

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. C:\fakepath\DocCloMac.odt

edit flag offensive delete link more


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?

Muru gravatar imageMuru ( 2017-12-02 15:01:37 +0100 )edit

answered 2017-12-02 15:53:55 +0100

Jim K gravatar image

updated 2017-12-03 05:07:00 +0100

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


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()

But the inner frame containing the document can still be closed, as explained at http://openoffice.2283327.n4.nabble.c.... 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

edit flag offensive delete link more


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, 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
Muru gravatar imageMuru ( 2017-12-02 16:17:24 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-12-01 18:16:24 +0100

Seen: 163 times

Last updated: Dec 03 '17