How to set a macro to an sheet-event by a macro

Hi,

my scenario is the following: I’m copying a sheet internally of a Libre Calc (4.4.5.2) document by a macro (Basic). In the (source-) sheet I’ve linked a script to a sheet-event (OnChange). By copying this (source-) sheet the new sheet has no macro defined for the sheet-event.
May there’s a way to solve this problem, but i don’t think so because if i do the copy manually the macro is also missing in the new sheet.

I thought that i could add the macro to the sheet-event via a script/macro, but i don’t find the right commands to do so.
May someone knows a howto?

Hi

For a sheet named Sheet2, to set OnDoubleClick a macro test stored in Module1 of the Standard library of the document:

sub Macro
dim Prop(1) as new com.sun.star.beans.PropertyValue

Prop(0).name = "EventType"
Prop(0).value = "Script"
Prop(1).name = "Script"
Prop(1).value = "vnd.sun.star.script:Standard.Module1.test?language=Basic&location=document" 

thiscomponent.sheets.getByName("Sheet2").Events.replaceByName("OnDoubleClick", Prop())

end sub

Event names available: “OnFocus”, “OnUnfocus”, “OnSelect”, “OnDoubleClick”, “OnRightClick”, “OnChange”,“OnCalculate”

Regards