Button Event Dynamic Persistant Oliver Brinzing Laurent Godard Tom Schindl I have a lot of controls (250 buttons) in a document and want to set their "when intiating" events dynamically

I want to do this only once on building the document so that, when the document is reloaded the events are still there.

(like if i do it manually with right click on the control and assign manually)

thanks to Oliver Brinzing

More than one vent can be registered even if the UI in design mode shows the last one

Option Explicit Sub SetEvent Dim oDocument as Object Dim oView as Object Dim oDrawPage as Object Dim oForm as Object Dim oEvents(0) as New com.sun.star.script.ScriptEventDescriptor oDocument = StarDesktop.getCurrentComponent oView = oDocument.CurrentController oDrawPage = oView.getActiveSheet.DrawPage ' get the first form oForm = oDrawPage.getForms.getByIndex(0) oEvents(0).ListenerType = "XActionListener" oEvents(0).EventMethod = "actionPerformed" oEvents(0).AddListenerParam = "" oEvents(0).ScriptType = "StarBasic" oEvents(0).ScriptCode = "document:Standard.Module1.Test" oForm.registerScriptEvent(0, oEvents(0)) End Sub Sub Test(oEvt) Print oEvt.Source.Model.Name End Sub
Modified to match new snippet-DTD Initial version