[Solved] Another Listener Problem

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
nckeeley
Posts: 4
Joined: Tue Nov 23, 2021 2:30 am

[Solved] Another Listener Problem

Post by nckeeley »

I've searched dozens of topics on the subject, but I still can't quite figure out what I'm doing wrong. I have a named range called "inputs" on Sheet1. When a value in that range changes, I get the message box popping up dozens of times before it disappears. Any help is much appreciated!

Code: Select all

'Gets spreadsheet to update as inputs change
Public oListener as Object
Public CellRng as Object

Public Sub AddListener
Dim Doc, Sheet, Cell as Object
Doc = ThisComponent
Sheet = Doc.Sheets.getByName("Sheet1")
CellRng = Sheet.getCellrangeByName("inputs")
oListener = createUnoListener("Modify_","com.sun.star.util.XModifyListener")  'create a listener
Cellrng.addModifyListener(oListener)  'register the listener
End Sub

Public Sub Modify_modified(oEvent)  'macro jumps here when oListener detects modification of Sheet
Call Calcs
End Sub

Public Sub Modify_disposing(oEvent)
End Sub

Public Sub ClearListener
Cellrng.removeModifyListener(oListener)  'remove the listener
End Sub

Public Sub Calcs
MsgBox "Something changed!"
end sub
Last edited by Hagar Delest on Wed Dec 01, 2021 9:00 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 4.1.11 on Windows 10 x64
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: Another Listener Problem

Post by JeJe »

How many times did you run the AddListener sub? Close and reload OO and run it once only and see how many times you get the msgbox.

Edit:
I tested with the attached document - no problem.
Attachments
Untitled 2.ods
(9.68 KiB) Downloaded 151 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
nckeeley
Posts: 4
Joined: Tue Nov 23, 2021 2:30 am

Re: Another Listener Problem

Post by nckeeley »

Thank you JeJe...
OpenOffice 4.1.11 on Windows 10 x64
Post Reply