Targeting Multiple Instances of Same Userform

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I have used some sample code from Mike Rickson where you can add additional instances of the same userform dynamically as shown in this post:


The approach is to do the following in summary:
Code:
    Rem show new instace of Me
        Set newInstanceOfMe = UserForms.Add(Me.Name)
        newInstanceOfMe.Show vbModeless
        
    Rem unload that UF
        'Unload newInstanceOfMe
        Set newInstanceOfMe = Nothing

I am using this code to create multiple userforms from right clicking on items in my dashboard i made. The issue is I have tons of public subroutines that modify the userform interface and are found in modules outside of the userform module itself. So this is an issue as the scope of these subroutines if the new instance button is pressed it targets the original form as the form name is hard coded into the subroutines. I want to dynamically add the object to target the correct form (the one with the button being pressed). I could go back and put all of these functions in the userform and set to private but that would take quite a while. Is there a way to target this new userform because it has the same name as the original so I cannot do Userform("Name").label.caption="blah BLah BLah" . Any advice would be appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Amend the code to take an object argument (the form in question) and then pass the form to the routine using the Me keyword, or the relevant object variable (eg newInstanceOfMe)
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,729
Members
448,294
Latest member
jmjmjmjmjmjm

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