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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show a form

Status
Not open for further replies.

aMember

Programmer
Jun 12, 2002
99
US
I'm running Excel 2002. I have a string that is the name of a form in my project. I want to be able to show this form. How can I do this? I tried using CallByName but cannot get it to work. (I am essentially creating a call stack. Hmm...do I have access to this?)

Any ideas?
 
I don't think it's possible to do what you want. Something like this is probably as close as you can get:
Code:
Option Explicit

Sub Demo()
  ShowForm "UserForm1"
End Sub

Sub ShowForm(FormName As String)
  If FormName = "UserForm1" Then UserForm1.Show
  If FormName = "UserForm2" Then UserForm2.Show
  If FormName = "UserForm3" Then UserForm3.Show
  If FormName = "UserForm4" Then UserForm4.Show
End Sub
 
Only way to do it that I know of is to create VBA code on the fly. That's a heavy-handed approach though - for most cases, Zathras' approach will be more convenient.
Rob
[flowerface]
 
If you want to implement Rob's suggestion to create VBA on the fly, take a look at my post in thread707-511608 for a way to fiddle code modules dynamically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top