Microsoft 365 TextBox avec heure

Le Rouky

XLDnaute Nouveau
Le Forum,

est-il possible dans un TextBox d'obtenir un résultat 01:25 (hh:mm) en entrant dans ce TextBox seulement 125?
si oui, comment faire?

actuellement j'ai :
VB:
Private Sub TextBox10_Change()
TextBox10.Value = Format (TextBox10.Value, "hh:mm")
End Sub

Cordialement
 
Dernière édition:
Solution
Bonjour à toutes & à tous, bonjour @Le Rouky
Essaie avec ce code :
Enrichi (BBcode):
Dim Auto As Boolean

Private Sub TextBox10_Change()
    If Auto Then Exit Sub
        If Len(Me.TextBox10) > 2 Then
            With Me.TextBox10
                Chaîne = Replace(.Text, ":", "")
                Chaîne = Format(Left(Chaîne, Len(Chaîne) - 2), "00") & ":" & Right(Chaîne, 2)
                Auto = True
                .Text = Chaîne
                Auto = False
            End With
        End If
End Sub
Amicalement
Alain

Modif (Textbox10 au lieu de Textbox1)

AtTheOne

XLDnaute Impliqué
Supporter XLD
Bonjour à toutes & à tous, bonjour @Le Rouky
Essaie avec ce code :
Enrichi (BBcode):
Dim Auto As Boolean

Private Sub TextBox10_Change()
    If Auto Then Exit Sub
        If Len(Me.TextBox10) > 2 Then
            With Me.TextBox10
                Chaîne = Replace(.Text, ":", "")
                Chaîne = Format(Left(Chaîne, Len(Chaîne) - 2), "00") & ":" & Right(Chaîne, 2)
                Auto = True
                .Text = Chaîne
                Auto = False
            End With
        End If
End Sub
Amicalement
Alain

Modif (Textbox10 au lieu de Textbox1)
 
Dernière édition:

Eric C

XLDnaute Barbatruc
Bonsoir le forum
Bonsoir Le Rouky, Alain

Voici un mix d'un code (de mes archives --Je n'ai plus le nom du créateur" mais bonsoir à lui s'il se reconnait) avec celui de notre ami AtTheOne qui vérifie que le nombre entré dans le TextBox soit bien de type horaire (pas trop français mais j'suis fatigué ce soir).
VB:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim heure As Date
With Me.TextBox1
If .Value = "" Then Exit Sub
If Not IsDate(.Value) Then
Cancel = True
.SelStart = 0
.SetFocus
.SelLength = Len(.Text)
Else
heure = .Value
.Value = Format(.Text, "hh:mm")
End If
End With
End Sub
 

Private Sub TextBox1_Change()
 Dim Auto As Boolean
  
    If Auto Then Exit Sub
        If Len(Me.TextBox1) > 2 Then
            With Me.TextBox1
                Chaîne = Replace(.Text, ":", "")
                Chaîne = Format(Left(Chaîne, Len(Chaîne) - 2), "00") & ":" & Right(Chaîne, 2)
                Auto = True
                .Text = Chaîne
                Auto = False
            End With
        End If
End Sub
Bonne nuit à toutes & à tous
@+ Eric c
 

Discussions similaires

Réponses
15
Affichages
425

Statistiques des forums

Discussions
311 725
Messages
2 081 940
Membres
101 845
dernier inscrit
annesof