Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel: Open a UserForm with defined name

Status
Not open for further replies.

dsantist

New member
Jan 31, 2007
1
Hi,

I'm new to the forums and i have (what i think to be) a fairly simple question...

In my code, i have a variable that represents the name of the UserForm that will be opened. How can I open the appropriate existing form based on this string representing the form name?

For instance, FormName = "UserForm_2"

Therefore, I want to open the existing form 'UserForm_2'.

I don't want to simply use UserForm_2.show because the value of the string (and therefore the form to be opened) will programmatically change depending on the circumstances.

Any ideas??

My first guess would be to use UserForm(FormName).Show , but this is not a built in function.

Thanx!
 
Replies continue below

Recommended for you

dsantist,

You can call userform by the index
Code:
UserForms.item(i).show
For more control in useform numbering define array of userform objects:
Code:
dim A(1 to 10) as Object
...
set A(1) = Userform1
...
set A(10) = Userform10
...
A(1).show

You cannot call Userforms("formname1").show like worksheets("Sheet1"). For more information search userform collection in VBA help.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor