Lasse said:
Hi
Is it possible to execute a macro when closing a form?
I have created a modeless form where I assign some new shortcuts when
opened and I would like to clear them when closing the form.
/Lasse
I'll assume that your "modeless form" is a UserForm. If that's true, then
you can put code in the UserForm_QueryClose procedure, which runs
automatically when the form is about to close (but before it actually
closes).
To create the proper procedure, go to the left-hand dropdown at the top of
the code window in the VBA editor and choose "UserForm"; then go to the
right-hand dropdown and choose "QueryClose". The full signature of the
procedure is
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
You probably won't need to use the parameters Cancel and CloseMode. You can
just insert the code that clears your shortcuts.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.