AW: Automatisch generierten CommandButton Code zuw.
18.09.2011 11:35:03
Peter
Vielen vielen herzlichen Dank!
Ich habs hinbekommen.
für alle dies vllt interessieren könnte hier mein Code:
in ein leeres Klassenmodul mit dem Namen CB_Bilder
Option Explicit
Public WithEvents CommandButton As MSForms.CommandButton
Private Sub CommandButton_Click()
Select Case CommandButton.t
Case 1
schalter1
Case 2
schalter2
Case 3
schalter3
End Select
End Sub
in den Code des UF:
Option Explicit
Dim CBCommands() As New CB_Bilder
Private Sub UserForm_Activate()
Dim cntBut As Control
Dim cntTXT As MSForms.Label
Dim intAnzahl As Integer
Dim intZahl As Integer
Dim intAbstand As Integer
Dim intAbstand0 As Integer
Dim b As Integer
Dim k As Integer
Dim i As Integer
Dim a As Integer
ReDim CBCommands(1 To 34)
intAnzahl = 34
intAbstand = 20
intAbstand0 = intAbstand
For k = 1 To 34
If ThisWorkbook.Sheets("Tabelle1").Range("D" & (8 + k)) "" Then
Set cntTXT = Bilder.Controls.Add("Forms.Label.1")
With cntTXT
.Left = 10
.Top = intAbstand
.Width = 100
.Height = 25
.Caption = ThisWorkbook.Sheets("Tabelle1").Range("D" & k )
End With
Set cntBut = Bilder.Controls.Add("Forms.CommandButton.1")
With cntBut
.Left = 110
.Top = intAbstand - 5
.Width = 100
.Height = 18
.Caption = "Bild laden"
End With
Set CBCommands(k).CommandButton = cntBut
Set cntTXT = Bilder.Controls.Add("Forms.Label.1")
cntTXT.Left = 220
cntTXT.Top = intAbstand
cntTXT.Width = 100
cntTXT.Height = 25
If ThisWorkbook.Sheets("Tabelle1").Range("BC" & k + 3).Value "" Then
cntTXT.Caption = Left(ThisWorkbook.Sheets("Tabelle1").Range("AY" & k + 3).Value, 10) _
Else
cntTXT.Caption = "Kein Bild"
End If
intAbstand = intAbstand + intAbstand0
End If
Next
With Bilder
' Höhe des Userforms
.Height = 500
' Scrollbar sichtbar
.KeepScrollBarsVisible = fmScrollBarsVertical
' Scrollbartyp vertikal
.ScrollBars = fmScrollBarsVertical
' Höhe des Scrollbereich in Abhängigkeit von der Anzahl der CommandButton
.ScrollHeight = 25 * (k + 1) / (1.15)
End With
End Sub
Ich bin wirklich begeistert von diesem Forum! Da bekommt man ja innerhalb von Minuten eine Antwort!
Vielen Dank nochmal!
Peter