0

I am creating some automation software for our company that dynamically creates pages on a Multipage depending on some data within a chosen excel file. I have controls set up on the object viewer with events to trigger (ie DblClick a ListBox or ComboBox).

This is my base UserForm with a Parent Multipage which contains a Listbox and another Multipage (child) that contains Frames with Labels, ComboBoxes, and Command Buttons.

How can I copy the events associated with an object to the new multipage?

I have started copying the existing objects already, but it's not complete.

I have been googling methods for copying events but the queries aren't relevant with certain KeyWords. I am looking into resources for Event Copying Now, but it seems to be limited. Seems the addressOf function on Copy event handler assignment to another instance is having issues when referencing another function.

ger_eazy
  • 9
  • 6
  • Your last link is to a VB.NET post. – Tim Williams Mar 03 '23 at 00:47
  • Well, that is embarrassing. – ger_eazy Mar 03 '23 at 16:19
  • If you need to handle events for dynamically-created controls, you can use something like a "control array", but it looks like it's going to take a bit of set-up with that many controls. Eg: https://stackoverflow.com/questions/48382957/how-to-add-events-to-dynamically-created-controls-buttons-listboxes-in-excel – Tim Williams Mar 03 '23 at 16:23
  • I have actually started making arrays for other control I will need around the form so that's not an issue. Can't really find the application in that example to copy a control though. – ger_eazy Mar 06 '23 at 15:07
  • I assumed you're not really copying but adding a new control? You can copy its properties one-by-one from the each existing control though. – Tim Williams Mar 06 '23 at 16:32
  • Referencing the first picture, I copy the ListBox on the left across as many pages as I need it. The ListBox currently works (on the first page), as a double click to enter into the ComboBoxes on the right in sequential order (already setup). I need the new ListBoxes on the new sheets to do something identical, just on their respective sheets. I can figure out how to index my pages to ensure it is going into the correct combo, however I am stuck at dynamically creating new events. – ger_eazy Mar 06 '23 at 16:37

1 Answers1

0

I have copied event triggers by following some of the references for event handlers within classes.

Created my own class to hold my ListBoxes and ComboBoxes and then allocated a dynamic array with the count of each needed. Associating the existing and new controls to the Class Array allowed the event handler to be used located within the Class.

Works like a charm! Classes Rule!

ger_eazy
  • 9
  • 6