Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to create a user form programmatically

Hello,
is there a way to create programmatically a userform with all the
"metadata" stored into a spreadsheet table?

For example:

col1 col2 col3
-------------- ---------- ------
CommandButton; PickList1; ;
ComboBox; SelCombo; 1,2,3

where col1 is the control type, col2 the control name e col3 the
controlsource (a string with item like "1,2,3")


The following procedure, based on a John Walkenbach article
http://j-walk.com/ss/excel/tips/tip76.htm,
work fine but only for a "one-dimensional" array


Private Sub ParamUserForm_Click()
Dim STArray() As Variant
Dim Cnt As Integer, i As Integer
Dim UserChoice As Variant
....


Cnt = ActiveSheet.Range("controls").Count
ReDim STArray(1 To Cnt)
For i = 1 To Cnt
STArray(i) =
ActiveSheet.Range("controls").Range("A1").Offset(i - 1, 0)
Next i
UserChoice = DynamicInputForm(STArray)
If UserChoice = False Then
'some code
End Sub


Function DynamicInputForm(OpArray)

Dim TempForm 'As VBComponent
Dim NewUserForm As Object
Dim CtlComboBox As Object
Dim CtlCommandButton As Object
....
Dim x As Integer, i As Integer, TopPos As Integer
....



Set NewUserForm = _
Application.VBE.ActiveVBProject.VBComponents.Add(v bext_ct_MSForm)

For i = LBound(OpArray) To UBound(OpArray)
If Not IsEmpty(OpArray(i)) Then
Select Case OpArray(i)

Case "ComboBox"
Set CtlComboBox =
NewUserForm.Designer.Controls.Add("Forms.ComboBox. 1")

With CtlComboBox
.Width = 60
.Height = 15
.Left = 8
.Top = TopPos
.Tag = i
.AutoSize = True
TopPos = TopPos + 15
End with

Case "CommandButton"
Set CtlCommandButton =
NewUserForm.Designer.Controls.Add("Forms.CommandBu tton.1")

With CtlCommandButton
'some properties
End with

End Select
End If
Next i

With NewUserForm
.name = "report trend line"
End With

' Add event-hander subs for the CommandButtons
'some code

' Pass the selected option back to the calling procedure
'some code

End Function

The problem come when, adding dinamically the .name (or the .caption)
properties of the ComboBox (commandbutton) or trying to populate the
combo, I need to reference a 3D array in the loop section (since
control type, control name and control source are stored in 3
different columns).

Thank you so much

Alberto Piazza
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create an user form to run macros in excel? mgj72394 Excel Discussion (Misc queries) 5 April 28th 07 06:40 PM
Can I create an Excel User Form without VB install on my PC? Novice Excel Discussion (Misc queries) 1 April 11th 06 04:05 PM
Looking to create a simple user form with lookup Tim Excel Discussion (Misc queries) 5 November 14th 05 04:57 PM
Excel VBA Programmatically delete a form? Anthony Keefe Excel Programming 0 August 30th 03 10:03 PM
How to create picklists programmatically Harald Staff[_4_] Excel Programming 0 July 16th 03 09:59 AM


All times are GMT +1. The time now is 03:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"