Besoin d un coup de pouce

Résolu
Esprit44 Messages postés 27 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 12 mai 2005 - 25 août 2004 à 16:26
Esprit44 Messages postés 27 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 12 mai 2005 - 26 août 2004 à 09:42
j ai un pb pour selectionner un texte situé entre 2 balises. Ca peut paraitre simple mais en fait voila ce se complique

Dans mon document, j ai des paragraphes identifié par des "<§"
Je lui demande donc au demarrage de les compter! jusque la j arrive

c'est apres lorque je lui demande de recuperer le titre de la futur checkbox situé juste apres cette balise que je galere. ce meme titre est lui meme situé entre 2 balises (pour le delimiter)
mais j arrive pas a le retrouver

si vous avez une idée sur le bout de code que je pourrais utiliser

voila ce que j ai mis mais ca fonctionne pas et vu mon niveu j ai du mal a l ameliorer

Merci bcp

ChRiS

Dim tempBoolean As Boolean

myRange.Find.Execute findtext:=TexteCherche
If myRange.Find.Found = True Then
tempBoolean = True
'on a trouve, maintenant on cherche le titre et on le met dans textTrouve <<<<< c'est à partir d ici que ca cloche
myRange.Select
Selection.EndKey Unit:=wdLine
With Selection.Find
.ClearFormatting
.Text = "<titre>"
.MatchWildcards = 0
.Forward = 1
.Replacement.Text = ""
.Replacement.ClearFormatting
.Execute ' recherche du mot1
Selection.MoveRight 'déplacement a droite du mot
.Text = "</titre>"
Selection.Extend ' etendre la selection
.Execute ' atteindre le mot2
Selection.MoveLeft Unit:=wdCharacter, Count:=Len("</titre>"), Extend:=1
' reculer du mot 2
End With
textTrouve = Selection
Else
tempBoolean = False
End If
Cherche = tempBoolean
End Function

3 réponses

TheEwook Messages postés 155 Date d'inscription samedi 3 juillet 2004 Statut Membre Dernière intervention 30 mai 2005
25 août 2004 à 16:56
Function sGetRightChamp(ByVal Ligne As String, ByVal leSeparateur As String, Optional ByVal Value As Variant) As String
    Dim nbCar As Integer, champ As String, lg As Integer
    
    
    champ = Ligne
    lg = Len(leSeparateur)
    
    If Len(champ) > 0 And lg > 0 Then
        ' Il faut prendre en compte la longueur du séparateur et le positionnement
        ' du séparateur détecté :        If lg 1 Then lg 0
        If lg > 1 Then lg = lg - 1
        
        ' Récupère une chaine de caractère à droite du séparateur.
        nbCar = InStr(champ, leSeparateur)              ' Nombre de caractere(s) a récupérer.
        'teXtt.TexT = nbCar
        If nbCar > 0 Then
            champ = Right(champ, Len(champ) - (nbCar + lg))     ' Mise à jour de la ligne sans le 1er champ.
        Else
            If IsMissing(Value) = False Then
                If CBool(Value) = True Then
                    champ = vbNullString
                End If
            End If
        End If
    End If
    
    sGetRightChamp = champ
End Function

Function sGetLeftChamp(ByVal Ligne As String, ByVal leSeparateur As String, Optional position As Variant) As String
    Dim nbCar As Integer, champ As String, pos As Integer
    
    
    pos = 0
    champ = Ligne
    
    If Len(champ) > 0 And Len(leSeparateur) > 0 Then        If IsMissing(position) False Then pos position
        
        ' Récupération du champ
        nbCar = InStr(champ, leSeparateur)
        
        ' Nombre de caractere(s) a récupérer.
        If nbCar > 0 Then champ = Left(champ, nbCar - 1)      ' Recuperation du champ.
    End If
    
    sGetLeftChamp = champ
End Function


Voilà 2 fonctions trés utiles. pour avoir ce que tu veux tu fais :

Dim titre As String
Dim Variable As String

Variable = "<§Voilà ton titre§>"

Titre = sGetLeftChamp(sGetRightChamp(Variable, "<§"), "§>")


Et donc la variable Titre devrait être égal à "Voilà ton titre"

voilà, normalement ca marche

@++

________________
TheEwook
3
TheEwook Messages postés 155 Date d'inscription samedi 3 juillet 2004 Statut Membre Dernière intervention 30 mai 2005
25 août 2004 à 16:58
P'tit erreur :

remplacer

Dim titre As String

par

Dim Titre As String


@++

________________
TheEwook
0
Esprit44 Messages postés 27 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 12 mai 2005
26 août 2004 à 09:42
Voila meric bcp pour cette merveilleuse fonction
en l adaptant j ai enfin reussi, je te remercie bcp tu viens de mettre fin a 2 jour de galere.

ChRiS
0
Rejoignez-nous