Ask Your Question

How to set a macro to an sheet-event by a macro [closed]

asked 2015-09-13 20:18:56 +0200

Tuennes gravatar image

updated 2020-08-25 20:03:14 +0200

Alex Kemp gravatar image


my scenario is the following: I'm copying a sheet internally of a Libre Calc ( 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?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-08-25 20:03:23.412564

1 Answer

Sort by » oldest newest most voted

answered 2015-10-01 10:12:37 +0200

pierre-yves samyn gravatar image


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

Prop(0).name = "EventType"
Prop(0).value = "Script"
Prop(1).name = "Script"
Prop(1).value = "" 

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

end sub

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


edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-09-13 20:18:56 +0200

Seen: 1,161 times

Last updated: Oct 01 '15