Guten morgen,
ich habe vor mit meinem Programm eine Exceldatei einzulesen. Diese enthält X Spalten.
Das Programm soll nun X-Textboxen erstellen (funktioniert auch)
Wie kann ich jetzt ein Change oder ein Keypress für die zur Laufzeit erstellten Felder abfangen?
Ziel ist es eine Live-Suche über ein Excel-Sheet zu kreieren. Also so, dass ich in Spalte 1 nach A suche in Spalte 2 nach B und ich dann in dem Flexgrid nur die Daten angezeigt bekomme, die in Spalte1 ein A haben und in Spalte2 ein B usw..
die Textfelder erzeuge ich wie folgt
Private Sub txt_ausgabe_OLEDragDrop(Data As DataObject, Effect As Long, Button _
As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Long
Dim links As Integer
links = 120
If Data.GetFormat(vbCFFiles) Then
If IsFileOpen(Data.Files.Item(1)) Then
MsgBox "Bitte Datei: " & Data.Files.Item(1) & " schließen."
Exit Sub
End If
Set oexl = Nothing
Set oexl = CreateObject("Excel.Application")
oexl.Visible = True
oexl.Workbooks.Open Data.Files.Item(1)
lastrow = getlastrow(oexl)
lastcolumn = oexl.ActiveWorkbook.ActiveSheet.Cells(1, _
oexl.ActiveWorkbook.ActiveSheet.Columns.count).End(xlToLeft).Column
excelarray = MoveSheetTobuffer(oexl, lastrow, lastcolumn)
For i = 1 To lastcolumn
Dim Textboxneu As TextBox
Set Textboxneu = Form1.Controls.Add("VB.TextBox", "txt" & i, Form1)
With Textboxneu
.Visible = True
.Width = 2175
.Height = 375
.Text = ""
.Top = 1560
.Left = links
links = links + 2300
End With
Next i
End If
End Sub ist es möglich ein event abzufangen? Mit vorher fest eingebauten Textfeldern kann ich die Suche so machen: (die Textfelder heißen jetzt genauso, nur funktioniert mein event nicht mehr...)
Private Sub txt1_Change()
Dim cnt As Long, count As Integer
text1 = txt1.Text
MSFlexGrid1.Clear
For cnt = 2 To lastrow
If InStr(UCase(excelarray(cnt, 1)), UCase(text1)) > 0 Then
If count < cut Then
MSFlexGrid1.TextMatrix(count, 0) = excelarray(cnt, 1)
MSFlexGrid1.TextMatrix(count, 1) = excelarray(cnt, 2)
MSFlexGrid1.TextMatrix(count, 2) = excelarray(cnt, 3)
MSFlexGrid1.TextMatrix(count, 3) = excelarray(cnt, 4)
MSFlexGrid1.TextMatrix(count, 4) = excelarray(cnt, 5)
count = count + 1
Else
Exit For
End If
End If
Next cnt
End Sub Wäre super wenn das schon jemand gemacht hat und weiß, ob es geht oder ob es sowieso gar nicht möglich ist zur Laufzeit erstellte Felder so abzufangen...zumal ich ja auch noch das Problem habe, dass ich ja nicht weiß, wieviele Felder es werden und ich somit ja auch die Events beliebig fortsetzen müsste...wenn ihr versteht, was gerade in meinem Kopf vorget
MfG
Florian |