Gruppe
Dialog
Problem
Die Breite einer UserForm-ComboBox soll während der Laufzeit in Abhängigkeit vom breitesten Inhalt festgelegt werden.
StandardModule: Modul1
Sub DialogAufruf()
frmListWidth.Show
End Sub
ClassModule: frmListWidth
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdListA_Click()
Dim iRow As Integer, iMax As Integer
Dim sTxt As String
cboList.Clear
For iRow = 1 To 12
sTxt = Format(DateSerial(1, iRow, 1), "mmmm")
cboList.AddItem sTxt
If Len(sTxt) > iMax Then iMax = Len(sTxt)
Next iRow
cboList.Width = iMax * 7
cboList.ListIndex = 0
End Sub
Private Sub cmdListB_Click()
Dim iRow As Integer, iMax As Integer
Dim sTxt As String
cboList.Clear
For iRow = 1 To 31
sTxt = "Asbach, den " & _
Format(DateSerial(Year(Date), 1, iRow), _
"dd. mmmm yyyy")
cboList.AddItem sTxt
If Len(sTxt) > iMax Then iMax = Len(sTxt)
Next iRow
cboList.Width = iMax * 7
cboList.ListIndex = 0
End Sub