Thema Datum  Von Nutzer Rating
Antwort
24.04.2025 17:25:25 Stefan
NotSolved
24.04.2025 18:41:24 Gast85797
NotSolved
24.04.2025 19:18:17 Gast2263
NotSolved
24.04.2025 20:41:33 xlKing
NotSolved
25.04.2025 19:36:20 Gast79359
NotSolved
26.04.2025 17:49:35 xlKing
NotSolved
Rot Aktion auslösen beim Verlassen einer TextBox
26.04.2025 21:41:07 Alwin Weisangler
NotSolved

Ansicht des Beitrags:
Von:
Alwin Weisangler
Datum:
26.04.2025 21:41:07
Views:
46
Rating: Antwort:
  Ja
Thema:
Aktion auslösen beim Verlassen einer TextBox

Hallo Stefan,

ins Modul des Userform:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Option Explicit
    Private msoTxt() As Cls_TextBoxen
 
Private Sub TextboxenBauen(ByVal oben As Double, ByVal links As Double, ByVal breite As Double, ByVal iTxt As Long)
    Dim i&, cTxt As MSForms.TextBox
    ReDim msoTxt(1 To iTxt)
    For i = 1 To iTxt
        Set cTxt = Controls.Add("Forms.TextBox.1", "TxtKanalEckig" & i, True)
        With cTxt
            .Top = oben
            .Left = links
            .Width = breite
            oben = oben + .Height + 5
        End With
        Set msoTxt(i) = New Cls_TextBoxen
        msoTxt(i).SetControlEvents(cTxt) = True
    Next i
End Sub
 
Private Sub UserForm_Activate()
    Call TextboxenBauen(oben:=30, links:=10.5, breite:=100, iTxt:=2)
End Sub

Klassenmodul Namens cls_TextBoxen:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Option Explicit
    Private coTextBox As Object
 
Public Property Let SetControlEvents(ByVal TextBox As Object, ByVal SetEvents As Boolean)
    Const AdrOK = &H0
    Static lCookie&
    Dim tIID As GUID
        Set coTextBox = TextBox
        If IIDFromString(StrPtr("{00020400-0000-0000-C000-000000000046}"), tIID) = AdrOK Then
            Call Ctcp(Me, tIID, SetEvents, TextBox, lCookie)
        End If
End Property
 
Public Sub OnExit(ByVal Cancel As MSForms.ReturnBoolean)
    With coTextBox
        If IsNumeric(coTextBox) And Left(coTextBox.Name, 13) = "TxtKanalEckig" Then
            MsgBox "Exit für " & .Name & " ausgelöst"
        End If
    End With
End Sub
 
Private Sub Class_Terminate()
    Set coTextBox = Nothing
End Sub

in ein allgemeines Modul:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Option Explicit
 
Public Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type
 
#If VBA7 Then
    Public Declare PtrSafe Function IIDFromString Lib "ole32.dll" (ByVal lpsz As LongPtr, lpiid As GUID) As Long
    Public Declare PtrSafe Function Ctcp Lib "shlwapi" Alias "#168" (ByVal punk As stdole.IUnknown, ByRef riidEvent As GUID, ByVal fConnect As Long, ByVal punkTarget As stdole.IUnknown, ByRef pdwCookie As Long, Optional ByVal ppcpOut As LongPtr) As Long
#Else
    Public Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, lpiid As GUID) As Long
    Public Declare Function Ctcp Lib "shlwapi" Alias "#168" (ByVal punk As stdole.IUnknown, ByRef riidEvent As GUID, ByVal fConnect As Long, ByVal punkTarget As stdole.IUnknown, ByRef pdwCookie As Long, Optional ByVal ppcpOut As Long) As Long
#End If

Gruß Uwe


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
24.04.2025 17:25:25 Stefan
NotSolved
24.04.2025 18:41:24 Gast85797
NotSolved
24.04.2025 19:18:17 Gast2263
NotSolved
24.04.2025 20:41:33 xlKing
NotSolved
25.04.2025 19:36:20 Gast79359
NotSolved
26.04.2025 17:49:35 xlKing
NotSolved
Rot Aktion auslösen beim Verlassen einer TextBox
26.04.2025 21:41:07 Alwin Weisangler
NotSolved