Probleme bei einer Klasse
12.02.2015 04:56:32
Patrick
ich scheitere gerade daran in einer Klasse in bei "Private Sub Class_Initialize()" meine Label anzusprechen.
In der Methode "Private Sub MyLabel_DblClick(ByVal Cancel As MSForms.ReturnBoolean)" schaffe ich das Problemlos. Mir ist das nicht ganz klar, den schließlich wird es mir auch vervollständigt, von daher müsste die Funktion ja da sein.
Auch wenn ich hier nur per MsgBox den Namen ausgebe, will ich eigentlich die .BackColor ändern. _
Habe es nur einmal zum Testen probiert, aber ich kriege es nicht hin. Vielen Dank für euere Hilfe.
Gruß Patrick
Hier mein Code dazu:
Option Explicit
Dim WinOrMac() As New clsWinOrMac
Private Sub UserForm_Initialize()
Dim cnt As Control
Dim MaWiLabelCount As Integer
Dim i As Integer
MaWiLabelCount = 0
' Anzahl der CommandButton ermitteln
For Each cnt In Controls
'Label sammeln für das Umfärben auf Windows
If TypeName(cnt) = "Label" Then
MaWiLabelCount = MaWiLabelCount + 1
End If
Next cnt
ReDim Preserve WinOrMac(MaWiLabelCount)
For i = 1 To MaWiLabelCount
Set WinOrMac(i).MyLabel = Controls("Label" & i)
Next i
End Sub
Public WithEvents MyLabel As MSForms.Label
Private Sub Class_Initialize()
MsgBox MyLabels.Caption
Me.Label.BackColor = &H8000000F
If InStr(Application.OperatingSystem, "Macintosh") Then
Else:
End If
End Sub
Private Sub MyLabel_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox MyLabel.Name
End Sub