1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Private start As Long
Private Sub CommandButton1_Click()
Dim cherche As String
cherche = "toto"
suivant cherche, start
End Sub
'
'
Private Sub suivant(cherche As String, start)
Dim i As Integer
With TextBox1
If start > .TextLength Then start = 0
For i = start To .TextLength
.SelStart = i
.SelLength = Len(cherche)
.SetFocus
If .SelText = cherche Then start = .SelStart + Len(cherche): Exit Sub
If i = Len(.Text) Then .SelStart = 0: start = 0 'ici ca fonctionne, ca revient bien en haut du texte du textbox
Next
End With
End Sub |