Ask Your Question

How to assign a macro to an event by a macro

asked 2021-03-05 22:19:34 +0200

gkick gravatar image

Win10 LO6.4.7.2 HSQL2.51

Hi all,

I would like a user to choose whether to be prompted for a login prompt or not. One can do this manually via the setup script which comes with the database split wizard(s)

image description

by simply uncommenting line 76

Thinking of a checkbox in an options form to toggle the login requirement and guess the easiest way would be to swap between 2 setup scripts. Now I found this brief code sometime somewhere and it seems to fit the purpose, however I think the last 2 lines prior to the end sub need to be adjusted to base

sub ForceMacro
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

The original setup macro is attached to the Customize, On Open Doc event The database window however does not seem to have a name but can be manipulated via

Const acDatabaseWindow = 102

Anyone come across a similar example ? Any pointers to what needs to be changed above will be greatly appreciated.


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2021-03-05 23:18:29 +0200

Ratslinger gravatar image

updated 2021-03-06 00:37:19 +0200


Do not under the reasoning (or even some logic - options form?) of why you are attempting this. Seems like a security issue lurking.

Edit: Regardless, your sample is not comparable to the request. It is a Event for a sheet and in comparison to modifying a form or control event, it is quite different.

You can access the Base and Form events with your code. Should be able to access with

ThisDatabaseDocument.Events.replaceByName("CHOSEN_EVENT", Prop())

End Edit

For Form controls (also for Base itself) see this post: How to programmatically get/set a form control's events

To go another step, see the answer in this post: Register macro to Image Button. It also contains another link to more info with included sample and cross reference list of events in controls (on Calc sheet).

edit flag offensive delete link more


@Ratslinger Thank you, just playing with ideas, the secrity issue aside I think using a macro to assign macros to events would be away to ensure macros are not removed from a form as you simply put them back. Thanks for the links

gkick gravatar imagegkick ( 2021-03-06 00:29:11 +0200 )edit

Thanks, will explore

gkick gravatar imagegkick ( 2021-03-06 02:24:41 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2021-03-05 22:19:34 +0200

Seen: 36 times

Last updated: Mar 06