Having trouble converting to LO from VBA. I have a calc sheet in which I wish to monitor 5 columns for changes. I have written the event code which works fine, except when I close the sheet I get the warning:
“Message: The following Basic script could not be found:
library: ‘Standard’
module: ‘Module1’
method: ‘RmvListener’
location: ‘document’”
Which is puzzling since the code is there
function Modify_RmvListener(oEv)
CellRng.removeModifyListener(oListener(a))
end function
oListener is acting on 5 columns (a=0 to 4)
Any pointers where to look to fix appreciated.
Edit 2019-04-09 (by Ratslinger) - Transfer data in not-an-answer answer to here:
Thanks very much, Kat. The progress to OO/LO coding from VBA has been painful largely due to the lack of code examples, unlike the VBA help side which often does contain these.
The code I am using was shamelessly lifted from a (rare) post on the OO forum in which the ever helpful FJCC posted it. Why he used Fn and non sub I know not.
‘a’ comes from
function add_listener
Dim Doc as Object
Dim Cellpos(5)
Cellpos(0)="A8:A260"
Cellpos(1)="F8:F260"
Cellpos(2)="G8:G260"
Cellpos(3)="K8:K260"
Cellpos(4)="N8:N260"
Doc = ThisComponent
Sheet = Doc.Sheets.getByIndex(0) 'get leftmost sheet
dim a
for a=0 to 4
CellRng = Sheet.getCellrangeByName(Cellpos(a))
oListener(a) = createUnoListener("Modify_","com.sun.star.util.XModifyListener") 'create a listener
Cellrng.addModifyListener(oListener(a)) 'register the listener
next a
end function
Re the fn call for RmvListener- yes, my original code was, as per FJCC,
function RmvListener
CellRng.removeModifyListener(oListener(a))
end function
but this was giving me a “BASIC runtime error. Variable not defined” warning when I closed the sheet and in the resulting blind thrashing around I tried the code I posted - which gave the new warning, but not the ‘variable’ warning. Commenting out the line ‘CellRng.removeModifyListener(oListener(a))’ stops the variable not defined warning.
If you can point to any source of LO/OO code sample I would appreciate it. How do I track down the Basic error on closing the sheet?