Ich habe so was in der Art mal gemacht
dazu habe ich in einem Model eine "Hilfs"funktion
definiert
Option Explicit
Public Const durch As Integer = 10
Public meine_Parent As Object
Public Function adden(meine_Userform, meine_Form, meine_Top, meine_Left, meine_Height, meine_Width, meine_name, Optional meine_Caption = "", Optional meine_BackColor = "&H80000005", Optional meine_Style = 2, _
Optional meine_Bold = False, Optional meine_Border = False, Optional meine_Enabled = True, Optional meine_Pages = 2, Optional meine_ForeColor = "&H80000012")
Dim temp
Dim modframe As Long
Dim lv As Long
If meine_Parent.Name = meine_Userform.Name Then
modframe = 0
Else
modframe = 45
End If
If meine_Form = "Frame" Then
Set temp = meine_Userform.Controls.Add("Forms." & meine_Form & ".1")
Set meine_Parent = temp
ElseIf meine_Form = "MultiPage" Then
Set temp = meine_Userform.Controls.Add("Forms." & meine_Form & ".1")
If meine_Pages = 1 Then
temp.Pages.Remove (1)
ElseIf meine_Pages > 2 Then
For lv = 1 To meine_Pages - 2
temp.Pages.Add
Next
End If
Set meine_Parent = temp.Pages(0)
ElseIf meine_Form = "SubFrame" Then
Set temp = meine_Parent.Controls.Add("Forms." & "Frame" & ".1")
Set meine_Parent = temp
Else
Set temp = meine_Parent.Controls.Add("Forms." & meine_Form & ".1")
End If
With temp
.Name = meine_name
.Height = meine_Height / durch
.Left = meine_Left / durch
.Top = (meine_Top - modframe) / durch
.Width = meine_Width / durch
Select Case meine_Form
Case "Label", "OptionButton", "CommandButton", "CheckBox", "Frame", "SubFrame", "ToggleButton"
.Caption = meine_Caption
If meine_Border = True Then
.BorderStyle = 1
End If
If meine_ForeColor <> "&H80000012" Then
.ForeColor = meine_ForeColor
End If
If meine_Form = "Frame" And meine_BackColor <> "&H80000005" Then
.BackColor = meine_BackColor
End If
Case "TextBox"
.text = meine_Caption
.BackColor = meine_BackColor
If meine_Enabled = False Then
.Enabled = False
End If
Case "ComboBox"
.Style = meine_Style
End Select
If meine_Form <> "SpinButton" Then
With .Font
.Size = 10
.Bold = meine_Bold
End With
End If
End With
Set adden = temp
Set temp = Nothing
End Function
und dann so aufgerufen
Option Explicit
Dim mein_Textbox
Dim mein_Fr01, mein_Lb01
Public WithEvents mein_Cmd As MSForms.CommandButton
Const meinFrame = "&H8000000F"
Private Sub UserForm_Initialize()
Dim Framework As Long
With UserForm1
.Caption = "mein Beispiel"
.Top = 10 / durch
.Left = 10 / durch
.Width = 600 / durch
.Height = 500 / durch
End With
Set meine_Parent = Me
Framework = 50
Call Modul1.adden(Me, "Frame", Framework, 10, 200, 500, mein_Fr01, meine_Caption:="Hallo Welt", meine_Bold:=True, meine_BackColor:=meinFrame)
Framework = Framework + 200
Call Modul1.adden(Me, "Label", 60, 20, 20, 80, "mein_Lb01", meine_Caption:="ich bins")
Set mein_Textbox = Modul1.adden(Me, "TextBox", 60, 120, 20, 300, "Txt_Firmenname", meine_Caption:="", meine_BackColor:=&H8000000D, meine_Enabled:=True)
Set mein_Cmd = Modul1.adden(Me, "CommandButton", 120, 30, 20, 100, "mein_Cmd", meine_Caption:="Starte", meine_Bold:=True)
Set meine_Parent = meine_Parent.Parent
End Sub
Set xxx = für alle Events oder noch anzusteuernde Formen
Call bei rein optischen Elementen (Frame, label)