Listening to the UserForm_Activate event using WithEvents in a Class Module.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,596
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Say for example, you have a couple of modeless userforms on display and you want to run some small macro each time you activate each userform.

The obvious answer is simply placing the small macro (or a call to it) in each of the UserForm_Activate event handlers.

But what If you wanted to have a common event handler in a class module that runs the common code (similar to what we do with form controls) ?

If you try using Private WithEvents uFormEVents As UserForm, you will find that the Actiavate\Deactivate events are not exposed by the class.

Yes. I have come up with some workarounds like subclassing the userforms ( and catching the WM_NCACTIVATE ) or using a windows timer to detect when the userforms are being activated but I am trying to avoid such approaches as they are both risky and have a heavy performance hit. I am looking for a more OOP oriented approach.

Does anyone have any suggestions ?

The subject of this recent thread is what prompted me to post this question.
 
If it was yours, do you think that other account could that have had an email address with a UK domain?
I was livng in the UK at the time and that's where and when I learned the little English I know. ?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
For anyone looking to group userforms together, here is this new thread where I posted a much better rmethod :
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top