online 1
gast (50)

/ Forum / Tabellenkalkulation

TabellenkalkulationTabellenkalkulation

Fragevon Kauz vom 02.05.2020, 20:22 Options

Userform / Textfeld / Setfocus

Hallo Excelgemeinde...

komme nach vielen Versuchen nicht zum gewünschten Ergebnis:

EinTabellenblatt ist komplett geschützt, und soll ausschließlich von einer Userform bedient werden.

Es geht hierbei um die Textfelder.....
Wenn ich zwei im Wechsel als Eingabe nutze, so ist es kein Problem diesen auch abwechselnt den Focus zuzuweisen.

Es gibt aber noch ein Textfeld, in dem auch mehrer Eingaben hintereinander gemacht werden sollen.
Nur schaffe ich es nicht, das nach der Return-Taste sich der Cursor wieder für die nächste Eingabe im Textfeld zeigt.

Hier der Code:

Private Sub TxtNotiz_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

' Die Variable aks beginnt bei der ersten Eingabe mit 0....
' sie wird bei Opt5 auf Null gesetzt

  If KeyCode = 13 Then
    If Opt5.Value = False Then
 ' Der Bereich ist für Einzeleingaben
    Else
      If aks = 0 Then Sheets("Eingabe").Txt11.Value = TxtNotiz.Value
      If aks = 1 Then Sheets("Eingabe").Txt12.Value = TxtNotiz.Value
      If aks = 2 Then Sheets("Eingabe").Txt13.Value = TxtNotiz.Value
      If aks = 3 Then Sheets("Eingabe").Txt21.Value = TxtNotiz.Value
      If aks = 4 Then Sheets("Eingabe").Txt22.Value = TxtNotiz.Value
      If aks = 5 Then Sheets("Eingabe").Txt23.Value = TxtNotiz.Value
      If aks = 6 Then Sheets("Eingabe").Txt31.Value = TxtNotiz.Value
      If aks = 7 Then Sheets("Eingabe").Txt32.Value = TxtNotiz.Value
      If aks = 8 Then Sheets("Eingabe").Txt33.Value = TxtNotiz.Value
      If aks = 9 Then Sheets("Eingabe").Txt41.Value = TxtNotiz.Value
      If aks = 10 Then Sheets("Eingabe").Txt42.Value = TxtNotiz.Value
      If aks = 11 Then Sheets("Eingabe").Txt43.Value = TxtNotiz.Value
      'If TxtNotiz.Value = "" Then Opt5.Value = False
      aks = aks + 1
      If aks = 12 Then Sheets("Eingabe").TxtNotiz.Enabled = False
      If aks = 1 Then Frame3.Caption = "Zweite Zeile für Pos 1"
      If aks = 2 Then Frame3.Caption = "Dritte Zeile für Pos 1"
      If aks = 3 Then Frame3.Caption = "Erste Zeile für Pos 2"
      If aks = 4 Then Frame3.Caption = "Zweite Zeile für Pos 2"
      If aks = 5 Then Frame3.Caption = "Dritte Zeile für Pos 2"
      If aks = 6 Then Frame3.Caption = "Erste Zeile für Pos 3"
      If aks = 7 Then Frame3.Caption = "Zweite Zeile für Pos 3"
      If aks = 8 Then Frame3.Caption = "Dritte Zeile für Pos 3"
      If aks = 9 Then Frame3.Caption = "Erste Zeile für Pos 4"
      If aks = 10 Then Frame3.Caption = "Zweite Zeile für Pos 4"
      If aks = 11 Then Frame3.Caption = "Dritte Zeile für Pos 4"
'----------- ab Hier soll Focus wieder auf's Textfeld--------
      TxtNotiz.Text = ""
      TxtNotiz.SetFocus
    End If
  End If
  Sheets("Eingabe").Protect
End Sub


Er landet trotz > Txtnotiz.setfocus < immer auf einer(der gleichen) Schaltfläche.
Voraussetzungen: Win XP / Excel2003

Mir fehlen einfach die Ereignisse GotFokus und Lostfokus.... ich meine, unter Excel97 und/ oder Excel2000 gab es diese noch.

Was kann da als Ersatz fungieren?

Ratlose Grüße
Andreas


Antwort schreiben

Antwort 1 von Hajo_Zi vom 04.05.2020, 14:16 Options

Hallo Andreas,

ich habe Dein Beispiel jetzt nicht nachgebaut, die Zeit zur Erstellung hast Du ja schon investiert.
Benutze das Exit Ereignis und mt Cancel=True, bleibt der Focus in der Textbox.

Gruß Hajo

Antwort 2 von Kauz vom 05.05.2020, 15:20 Options

Hallo Hajo...
Hab Deinen Tipp probiert:

Textfeld steckte in einem Frame... nun ist es direkt auf der Userform. (Damit es einfacher wird)
Habe in den Ereignissen <Enter> und <Exit> eine msgbox eingebaut...
Dannach zu urteilen, bleibt der Fokus auf dem Textfeld.

Es wird allerdings kein Cursor angezeigt, und eine Eingabe zu tätigen ist nicht möglich.

Hast Du vielleicht noch eine Idee?

Gruß
Andreas

Antwort 3 von Hajo_Zi vom 05.05.2020, 15:24 Options

Hallo Andreas,

ich habe es gerade getestet ohne Probleme
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox 1
Cancel = True
End Sub
Ein Nachbau sieht aber meist anders aus als das Original.

Gruß Hajo

Antwort 4 von Kauz vom 05.05.2020, 22:50 Options

Hallo Hajo,
dann werde ich mal einen Rückbau vornehmen:

Ich erstelle eine neue Tabelle nur mit den für diese Funktion relevanten Elementen.
Vielleicht ergibt sich ja ein Problem an einer ganz anderen Stelle?

Also Schritt für Schritt erweitern, und schauen ab wann sich dieser Effekt einstellt.

Ich bedanke mich erstmal für Deine Bemühungen.....

Evtl. frag ich nochmal nach....

Gruß
Andreas

Ähnliche Themen

UserForm Textfeldeingabe begrenzen
enibas74  14.07.2007 - 28 Hits - 1 Antwort

Excel benutzen, trotz offener Userform
BlauLED  22.10.2007 - 162 Hits - 1 Antwort

Textfeld VBA
ro05  14.04.2008 - 33 Hits - 1 Antwort

UserForm ComboBox
fedjo  26.04.2008 - 42 Hits - 3 Antworten

UserForm ListBox
fedjo  15.06.2008 - 166 Hits - 8 Antworten

Hinweis

Diese Frage ist schon etwas älter, Sie können daher nicht mehr auf sie antworten. Sollte Ihre Frage noch nicht gelöst sein, stellen Sie einfach eine neue Frage im Forum..

Neue Einträge

Version: supportware 1.9.150 / 10.06.2022, Startzeit:Mon Jan 26 16:59:01 2026