bonjour, je vous joint ci apres le code pour decouper une phrase en deux, ma question c 'est comment faire en utilisant ce code pour arrivé a décoper une phrase en deux si la phrase depasse un certaine nombre de caractere au lieu de tester par le nombre de mots et faire introduire "-" si il y'as eu une copure d'un mot.
merci pour votre aide
Function PremiersMots(Phrase As String)
Application.Volatile
Dim I As Integer, Compteur As Integer, Longueur As Integer
For I = 1 To Len(Phrase)
If Mid(Phrase, I, 1) = " " Then
Compteur = Compteur + 1
End If
If Compteur = 5 Then ' Nombre de mots à garder
Longueur = I - 1
Exit For
End If
Next I
If Longueur = 0 Then
PremiersMots = Phrase
Else
PremiersMots = Mid(Phrase, 1, Longueur)
End If
End Function
Function DerniersMots(Phrase As String)
Application.Volatile
Dim I As Integer, Compteur As Integer, Longueur As Integer
For I = 1 To Len(Phrase)
If Mid(Phrase, I, 1) = " " Then
Compteur = Compteur + 1
End If
If Compteur = 5 Then ' Nombre de mots à effacer
Longueur = I + 1
Exit For
End If
Next I
If Longueur = 0 Then
DerniersMots = ""
Else
DerniersMots = Mid(Phrase, Longueur, Len(Phrase) - Longueur + 1)
End If
End Function
merci pour votre aide
Function PremiersMots(Phrase As String)
Application.Volatile
Dim I As Integer, Compteur As Integer, Longueur As Integer
For I = 1 To Len(Phrase)
If Mid(Phrase, I, 1) = " " Then
Compteur = Compteur + 1
End If
If Compteur = 5 Then ' Nombre de mots à garder
Longueur = I - 1
Exit For
End If
Next I
If Longueur = 0 Then
PremiersMots = Phrase
Else
PremiersMots = Mid(Phrase, 1, Longueur)
End If
End Function
Function DerniersMots(Phrase As String)
Application.Volatile
Dim I As Integer, Compteur As Integer, Longueur As Integer
For I = 1 To Len(Phrase)
If Mid(Phrase, I, 1) = " " Then
Compteur = Compteur + 1
End If
If Compteur = 5 Then ' Nombre de mots à effacer
Longueur = I + 1
Exit For
End If
Next I
If Longueur = 0 Then
DerniersMots = ""
Else
DerniersMots = Mid(Phrase, Longueur, Len(Phrase) - Longueur + 1)
End If
End Function