2

How do we import the listener events of LibreOffice writer in Visual Basic 6?

I am trying to create a UNO service to get container listener event like following code,

Dim oListener As Object
oListener = CreateUnoListener("ContListener_", 
    "com.sun.star.container.XContainerListener")

I am getting an error

Compile error : Sub or Function not defined

Can anyone please help?

Raja Sahe S
  • 587
  • 1
  • 7
  • 13

1 Answers1

1

As explained here, CreateUnoListener does not work in VB6. So instead, it is necessary to implement the listener interface a different way.

Here is a VBScript example from https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Document_Events.

set xContext = objServiceManager.getPropertyValue( "DefaultContext" )
set xCoreReflection = xContext.getValueByName( "/singletons/com.sun.star.reflection.theCoreReflection" )
set xClass = xCoreReflection.forName( "com.sun.star.document.XEventBroadcaster" )
set xMethod = xClass.getMethod( "addEventListener" )

dim invokeargs(0)
invokeargs(0) = myListener

set value = objServiceManager.Bridge_GetValueObject()
call value.InitInOutParam("[]any", invokeargs)
call xMethod.invoke( objDocument, value )

Define a subroutine called myListener.

It may also help to check out the information at https://www.openoffice.org/udk/common/man/tutorial/office_automation.html.

There is a discussion of someone attempting similar code at https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=14217, although the final solution uses Javascript.

Disclaimer: I do not have any way to test VB6 code, so this information may not be entirely accurate. If you switch to Python or another language commonly used with LibreOffice then I can be of more help.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thanks for your quick response. Still I need an example of implementing a listener using listener interface with an explanation because am new to the UNO technology. – Raja Sahe S Oct 31 '17 at 18:49
  • Most likely you will not find any good examples for VB6, so I recommend using a more popular language since you are inexperienced. I can easily provide examples for Python, LO Basic or Java. Javascript, C++ and C# are also possible. – Jim K Oct 31 '17 at 20:29
  • I cannot get an example so far on this. Can you suggest any other ways to get clarified with. In my job, I am really in need of this information. – Raja Sahe S Nov 01 '17 at 09:53
  • @JimK I am interested to have an example in Java of XPropertyChangeListener... – JohnRDOrazio Oct 26 '20 at 08:15
  • @JohnRDOrazio You should ask a new question. However there are already several examples in Java such as https://api.libreoffice.org/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java. Google "java xpropertychangelistener libreoffice". – Jim K Oct 27 '20 at 13:04