AW: Hilfe Combobox Variable
Ramses
Hallo
warum erstellst du dann die Textfelder nicht zur Laufzeit ?
Kopier mal den Code in eine leere UF und öffne sie dann :-)
Private Sub UserForm_Initialize()
'Variablen setzen
Dim plTop As Integer, plHeight As Integer, plWidth As Integer, plLeft As Integer
Dim ufHeigth As Integer, ufWidth As Integer
Dim hSpace As Integer, vSpace As Integer
Dim i As Integer, n As Integer
Dim MyCtrl As Control
Dim txtBox1 As Integer, txtBox2 As Integer
'Userform erstellen
vSpace = 5
hSpace = 5
plTop = 5
plWidth = 50
plHeight = 15
plLeft = 10
'userformgrösse abfragen
txtBox1 = InputBox("Wieviele Textboxen möchten Sie erstellen", "Initialisierung", 50)
If txtBox1 Mod 10 <> 0 Then
MsgBox "auf die Schnelle nur mit geraden Zahlen"
Exit Sub
End If
If txtBox > 100 Then
MsgBox "Soviele sollten es nicht sein ;-)"
Exit Sub
End If
txtBox2 = InputBox("Wieviele Textboxen sollen untereinander stehen", "Initialisierung", Int(txtBox1 / 5))
If txtBox > txtBox1 Then
MsgBox "Das sind mehr als erstellt werden sollen ;-)"
Exit Sub
End If
ufHeigth = ((txtBox2 * plHeight) + ((txtBox2 * vSpace) + (4 * vSpace))) + 40
ufWidth = (Int((txtBox1 / 10)) * plWidth) + (Int((txtBox1 / 10)) * 10) + (4 * hSpace)
Debug.Print "Höhe: " & ufHeigth
Me.Height = ufHeigth
Me.Width = ufWidth
For i = 1 To (txtBox1 / txtBox2)
For n = 1 To txtBox2
Set MyCtrl = Controls.Add("Forms.Textbox.1")
MyCtrl.Left = plLeft
MyCtrl.Top = plTop
MyCtrl.Width = plWidth
MyCtrl.Height = plHeight
MyCtrl.name = "Textbox" & i
plTop = plTop + plHeight + 5
Next n
plTop = 5
plLeft = plLeft + plWidth + hSpace
Next i
'Schaltfläche hinzufügen
Debug.Print "Top: " & ufHeigth - (2 * plHeight + 20)
Set MyCtrl = Controls.Add("Forms.textbox.1")
MyCtrl.Left = 2 * vSpace
MyCtrl.Top = ufHeigth - (2 * plHeight + 20)
MyCtrl.Width = (3 * plWidth) + (2 * plWidth)
MyCtrl.Height = plHeight
MyCtrl.name = "txtLabel" & i
MyCtrl.Value = "That's real VBA Life ;-)"
End Sub
Gruss Rainer