VB and VBA Users Source Code: Loading/showing a form dynamically using the form name
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Loading/showing a form dynamically using the form name
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Sunday, June 25, 2000
Hits:
873
Category:
Windows Forms/GUI/Controls/Graphics
Article:
If you want to load/show a UserForm dynamically based on a variable, use the following code: For VBA use: Sub FormShow(sFormName As String) VBA.UserForms.Add(sFormName).Show End Sub For VB use: Sub FormShow(sFormName As String) VB.Forms.Add(sFormName).Show End Sub Or if you want to load a form, use: For VBA use: Function FormLoad(ByVal sFormName As String) As UserForm Set FormLoad = VBA.UserForms.Add(sFormName) End Sub For VB use: Function FormLoad(ByVal sFormName As String) As Form Set FormLoad = VB.Forms.Add(sFormName) End Sub and to call this routine you would use: 'VB Example Sub ExampleGetForm() Dim frmLoad As Form Set frmLoad = FormLoad("Form1") frmLoad.Show End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder