Ask Your Question
0

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

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

Muru gravatar image

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

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

Comments

Should be combined with https://ask.libreoffice.org/en/questi.... Basically a duplicate.

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

2 Answers

Sort by » oldest newest most voted
0

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

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

Comments

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 +0200 )edit
0

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

Jim K gravatar image

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

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 https://forum.openoffice.org/en/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.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 https://forum.openoffice.org/en/forum....

edit flag offensive delete link more

Comments

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

Question Tools

1 follower

Stats

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

Seen: 218 times

Last updated: Dec 03 '17