Hi,
My approach is very similar to Greg M's approach. See the attached file which contains static CommandButtons and Dynamic Command Buttons (created at runtime).
Instructions for creating a Class Event Handler:
a. To prevent a compile error, in the VBA Editor add the following library reference:
Tools -> References -> Microsoft Forms 2.0 Object Library (Excel 2003 version)
b. Create Class ClassCommandButton
The following line is required at the top of the Class:
Public WithEvents CommandButtonGroup As MSForms.CommandButton
There are several built in events that can be selected.
c. Put the following line at the top of an ordinary Code module:
Public myCommandButtons() As New ClassCommandButton
d. Put the following calls in UserForm_Initialize:
(1) - Call CreateUserForm1DynamicCommandButtons 'To CREATE Dynamic (created at runtime) controls
(2) - Call GenerateUserForm1CommandButtonControlArray 'To assign CommandButtons to the CommandButtonGroup
Controls in the CommandButtonGroup will have events handled by ClassCommandButton
NOTE: If a UserForm Event exists, it will still be activated before the Class Event.
In Class Module ClassCommandButton:
In the UserForm1 code module:
In an ordinary code module such as Module1:
Lewis
Bookmarks