HERBERS
Excel-Forum
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Entdecke rund 2 Millionen Excel-Lösungen im
Forumsarchiv
Forumbeitrag
Excel-Version des Fragestellers:
2010
Erfahrungslevel des Fragestellers:
Basiskenntnisse in VBA
Sumbu
10.05.2026 07:14:23
AW: Controls mit Events in Collections verwalten
Hallo snb, Hallo Ulf

snb, danke für die eine schön rote Textbox, aber was hat das mit der Überwachung der Events eines Textbox-Arrays zu tun?

Ulf, Du bist schon näher an meinem Problem dran, allerdings erzeugst du genau eine Textbox die du dann in der Watcher-Klasse überwachst. Ich brauche das allerdings für ein Array von Textboxen, damit ich die Werte an eine Datenklasse übergeben kann. Damit Du siehst was ich meine, hab ich mal einen kleinen Beispielcode geschrieben, in dem ich so ein Textbox-Array erszeuge.

Im Userform-Code:
Option Explicit


Private Sub UserForm_Initialize()

'Beispielwerte, ersetzen hier den jeweiligen .Count der Datenklassen:
Const mRows = 10
Const mCols = 5

With Me
.Height = mRows * 20
.Width = mCols * 60
.StartUpPosition = 0
.Caption = "GridEditor"
End With

Call fillTbGrid(mRows, mCols)

End Sub

Private Sub fillTbGrid(mRows As Long, mCols As Long)
Dim X As Long, Y As Long

For X = 1 To mRows
For Y = 1 To mCols
Call newControl(Me, "Tb" & CStr(X) & "-" & CStr(Y), _
"TextBox", (Y * 60 - 60), (X * 20 - 20), 23, 63, , 1)
Next Y
Next X

End Sub


In einem Standardmodul:
Option Explicit


Option Private Module

Public Function newControl(ByRef pvobjParent As Object, ByVal pvstrNamen As String, ByVal pvstrType As String, _
Optional ByVal pvsngLeft, Optional ByVal pvsngTop, Optional ByVal pvsngHeight, Optional ByVal pvsngWidth, _
Optional ByVal pvintSFX, Optional ByVal pvintBorderStyle, Optional ByVal pvlngHGFarbe, Optional ByVal pvlngVGFarbe, Optional ByVal pvstrCaption) As Control

Set newControl = pvobjParent.Controls.Add("Forms." & pvstrType & ".1", pvstrNamen, True)
With newControl
If Not IsMissing(pvsngLeft) Then .Left = pvsngLeft
If Not IsMissing(pvsngTop) Then .Top = pvsngTop
If Not IsMissing(pvsngHeight) Then .Height = pvsngHeight
If Not IsMissing(pvsngWidth) Then .Width = pvsngWidth
If Not IsMissing(pvintSFX) Then .SpecialEffect = pvintSFX
If Not IsMissing(pvintBorderStyle) Then .BorderStyle = pvintBorderStyle
If Not IsMissing(pvlngHGFarbe) Then .BackColor = pvlngHGFarbe
If Not IsMissing(pvlngVGFarbe) Then .ForeColor = pvlngVGFarbe
If Not IsMissing(pvstrCaption) Then
On Error Resume Next
.Caption = pvstrCaption
.Text = pvstrCaption
On Error GoTo 0
End If
End With
End Function


Vielen Dank schonmal und schönen Sonntag



Als Antwort auf diesen Beitrag
Ulf
09.05.2026 22:21:15
AW: Controls mit Events in Collections verwalten
Hi,
Prinzip
Userform
Option Explicit


Public t As clsTextbox

Private Sub CommandButton1_Click()
Dim f As MSForms.TextBox
Set f = Me.Controls.Add("Forms.TextBox.1")
Set t = New clsTextbox
Set t.TxtBox = f
With t.TxtBox
.Left = 10
.Top = 10
.Name = "ID"
.Value = 10
End With
End Sub

Klasse
Option Explicit


Public WithEvents TxtBox As MSForms.TextBox


Private Sub TxtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
MsgBox Me.TxtBox.Name
End Sub

hth
Ulf
Folgenachrichten
Antwort auf Beitrag erstellen
Bitte einen Anwendernamen ohne @ eingeben.
Bitte das Passwort eingeben.
Bitte eine gültige E-Mail-Adresse eingeben.
Bitte einen Betreff eingeben.
Weitere Optionen
Aktivieren, wenn die Frage/der Beitrag noch nicht beantwortet wurde und unter Listen > Offene Threads erscheinen soll.
Beispieldatei hochladen

Bitte einen Nachrichtentext eingeben.