Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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
Joined
Jan 31, 2007
Messages
1
Location
US
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!
 
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

Back
Top