Ask Your Question

How to raise a OnLoad event for writer document of LibreOffice from VB.Net/C#? [closed]

asked 2017-11-12 15:54:36 +0200

Muru gravatar image

updated 2020-09-02 22:16:07 +0200

Alex Kemp gravatar image

I am searching some example VB.NET/C# code to raise OnLoad & OnSave events for LibreOffice Writer document.

So referring the below code from the link ''. Here please anyone can tell how to get object and assign to variable 'Dim xContainer As XContainer ='



Module Module1 Sub Main()
    Dim oSM
    Dim oDesk, oDoc As Object
    Dim arg(-1)
    oSM = CreateObject("")
    oDesk = oSM.createInstance("")
    oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
    Dim xContainer As XContainer =  REM # TODO: Get object you want to listen to
    Dim myListener As MyListener = New MyListener()
End Sub
Class MyListener
    Implements XContainerListener
    Sub disposing(oEvent As EventObject) Implements XEventListener.disposing
    End Sub
    Sub XContainerListener_elementInserted([Event] As ContainerEvent) Implements XContainerListener.elementInserted
    End Sub
    Sub XContainerListener_elementRemoved([Event] As ContainerEvent) Implements XContainerListener.elementRemoved
    End Sub
    Sub XContainerListener_elementReplaced([Event] As ContainerEvent) Implements XContainerListener.elementReplaced
    End Sub
End Class

End Module

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-10-19 23:11:24.689914

1 Answer

Sort by » oldest newest most voted

answered 2017-11-13 21:12:19 +0200

Jim K gravatar image

updated 2017-11-13 21:15:34 +0200

Start with the WriterDemo example as described at Add the following code at the end of the Main() subroutine.

    Dim myListener As MyListener = New MyListener()
    Dim docEventBroadcaster As XDocumentEventBroadcaster = DirectCast(
        xComponent, XDocumentEventBroadcaster)
    For waitForEvents = 1 To 100
End Sub

Class MyListener
    Implements XDocumentEventListener
    Public Sub disposing(Source As Implements
    End Sub

    Public Sub documentEventOccured(oEvent As DocumentEvent) Implements XDocumentEventListener.documentEventOccured
        MsgBox("documentEventOccured " & oEvent.EventName)
    End Sub
End Class

To test, run the code and save the document, which should cause the message box to be displayed showing the events that occurred.

API documentation is at

edit flag offensive delete link more


Hi Jim, The provided solution is working well... :) Thanks a lot

Muru gravatar imageMuru ( 2017-11-14 08:01:57 +0200 )edit

Glad to hear it was helpful.

Jim K gravatar imageJim K ( 2017-11-14 16:16:45 +0200 )edit

Question Tools

1 follower


Asked: 2017-11-12 15:54:36 +0200

Seen: 391 times

Last updated: Nov 13 '17