Setting event handler in basic (solved)

It is a simple matter to associate a macro with an event using the Tools-Customise menu. Is there an equally simple way to do this from basic? The event handler stuff seems very complicated for something which is so simple by manual means. Specifically I want an impress file to do something when the presentation closes (OnViewClosed).

I’ve found the answer to this by modifying pierre-yves’ (to whom thanks) code in:

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.ImpressModule.ExitStuff?language=Basic& location=document" 
ThisComponent.Events.ReplaceByName("OnViewClosed", Prop())

Simples!