IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Word Discussion :

Méthode recherche à partir du mot sélectionné


Sujet :

VBA Word

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2012
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2012
    Messages : 50
    Points : 35
    Points
    35
    Par défaut Méthode recherche à partir du mot sélectionné
    Bonjour

    j'ai une méthode de recherche qui fonctionne. Par contre je n'arrive pas à résoudre un petit problème. J'aimerais que la recherche commence à partir du mot sélectionné et actuellement elle commence au début...
    Est-ce que quelqu'un pourrait m'aider?

    Merci d'avance


    Voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
     
    Dim chaine As String, tmp As String
    Dim bool As Boolean
    Dim start As Long
    Dim occu As Integer
    Dim nbOcc As Integer
    Dim Plage As Object, Wrd As Object
    Dim Cible As String
     
     
    Private Sub BUT_Next_Click()
     
            tmp = searchingForw()
     
     
     
    End Sub
     
     
    Private Sub BUT_Previous_Click()
     
            tmp = searchingBack()
     
    End Sub
     
    Private Sub UserForm_Initialize()
     
        count = 0
        chaine = ActiveDocument.Range(Selection.start, Selection.End)
        If Right(chaine, 1) = Chr(13) Then
            MsgBox chaine & " !!"
            chaine = Left(chaine, Len(chaine) - 1)
            MsgBox chaine & " !!"
        End If
     
        chaine = Trim(chaine)
     
        With ActiveDocument.Content.Find
            Do While .Execute(findText:=chaine, Format:=False, MatchCase:=False, MatchWholeWord:=False) = True
                count = count + 1
                MsgBox count
            Loop
        End With
     
        start = Selection.start
        MsgBox start
        If count = 0 Then
            MsgBox "Veuillez sélectionner un texte"
            Exit Sub
     
        End If
     
     
    End Sub
     
     
    Function searchingForw()
     
        ActiveWindow.LargeScroll (2)
        ActiveWindow.ScrollIntoView Obj:=Selection.Range, start:=True
        If ActiveWindow.Split = False Then
            ActiveWindow.Split = True
        End If
     
        ActiveWindow.Panes(2).Activate
     
        chaine = Trim(chaine)
     
        'recherche notre mot
        With Selection.Find
            .ClearFormatting
            .Text = chaine
            .Forward = True
     
            While .Execute
                start = Selection.End + 1
                .Wrap = wdFindAsk
     
                Exit Function
     
            Wend
        End With
     
        searchingForw = chaine
     
    End Function
     
     
    Function searchingBack()
     
        ActiveWindow.LargeScroll (2)
        ActiveWindow.ScrollIntoView Obj:=Selection.Range, start:=True
        If ActiveWindow.Split = False Then
            ActiveWindow.Split = True
        End If
     
        ActiveWindow.Panes(2).Activate
        chaine = Trim(chaine)
     
        'recherche notre mot
        With Selection.Find
            .ClearFormatting
            .Text = chaine
            .Forward = False
     
            While .Execute
                start = Selection.start - 1
                .Wrap = wdFindAsk
     
                Exit Function
     
            Wend
        End With
     
        searchingBack = chaine
     
    End Function
     
     
    Private Sub BUT_Close_Click()
    If ActiveWindow.Split Then
            ActiveWindow.Panes(2).Close
        End If
        Unload Search
    End Sub

  2. #2
    Membre expert

    Homme Profil pro
    Spécialiste progiciel
    Inscrit en
    Février 2010
    Messages
    1 747
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Loire (Auvergne)

    Informations professionnelles :
    Activité : Spécialiste progiciel
    Secteur : Service public

    Informations forums :
    Inscription : Février 2010
    Messages : 1 747
    Points : 3 016
    Points
    3 016
    Par défaut
    Bonjour,

    La recherche a lieu sur tout le document :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    With ActiveDocument.Content.Find
    Il faudra le remplacer par un range défini du début de la sélection à la fin du document.
    Cordialement,
    Christophe

    Merci de ne pas oublier de mettre résolu quand le sujet l'est. Cela aide tous les DVPnautes dans leur recherche

Discussions similaires

  1. Recherche de PDF à partir de mot clé
    Par hajar80 dans le forum C#
    Réponses: 4
    Dernier message: 21/04/2011, 13h37
  2. Réponses: 8
    Dernier message: 11/08/2009, 09h07
  3. Recherche à partir du champ dbedit sélectionné
    Par LuckyLuke56 dans le forum Langage
    Réponses: 3
    Dernier message: 20/07/2009, 13h41
  4. [WD-2003] Recherche Remplac de mots à partir d'une liste
    Par rosemary_antoine dans le forum VBA Word
    Réponses: 25
    Dernier message: 12/06/2009, 15h26
  5. Afficher à partir du mot recherché par un grep
    Par petdelascar dans le forum Applications et environnements graphiques
    Réponses: 5
    Dernier message: 15/11/2007, 13h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo