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 :

Fonction pour remplacer des motifs de mots par d'autre


Sujet :

VBA Word

  1. #1
    Membre régulier Avatar de keketteboy
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mai 2008
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence

    Informations forums :
    Inscription : Mai 2008
    Messages : 100
    Points : 73
    Points
    73
    Par défaut Fonction pour remplacer des motifs de mots par d'autre
    Bonjour à toute la communauté.

    Je voudrais me faire une macro me permettant de remplacer certains motifs dans mes fichiers texte pour éviter d'utiliser la fonction "remplacer par" parce que ça devient très long et fastidieux quand on a plein de motifs et plein de fichiers. Je suis novice en la matière. Merci pour votre aide précieuse.

  2. #2
    Rédacteur/Modérateur

    Avatar de Heureux-oli
    Homme Profil pro
    Contrôleur d'industrie
    Inscrit en
    Février 2006
    Messages
    21 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : Belgique

    Informations professionnelles :
    Activité : Contrôleur d'industrie
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 21 087
    Points : 42 926
    Points
    42 926
    Par défaut
    Salut,

    Qu'entends-tu par motif ?

  3. #3
    Membre régulier Avatar de keketteboy
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mai 2008
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence

    Informations forums :
    Inscription : Mai 2008
    Messages : 100
    Points : 73
    Points
    73
    Par défaut
    Bonjour.

    Tout d'abord merci pour l'intérêt que tu me portes. Ce que j'entends par "motif", c'est à dire un pattern qui revient souvent dans mon fichier comme ",00" ou les voyelles avec accents. Voici ce que j'ai fait mais je ne comprends pas pourquoi ça ne marche pas sur des grands fichiers.
    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
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
     
    Sub ChercheEtRemplace()
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = " 00:00:00"
        .Text = ",00"
        With .Replacement
            .ClearFormatting
            .Text = ""
            .Text = ""
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = ",10"
        .Text = ",20"
        With .Replacement
            .ClearFormatting
            .Text = ",1"
            .Text = ",2"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = ",30"
        .Text = ",40"
        With .Replacement
            .ClearFormatting
            .Text = ",3"
            .Text = ",4"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = ",50"
        .Text = ",60"
        With .Replacement
            .ClearFormatting
            .Text = ",5"
            .Text = ",6"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = ",70"
        .Text = ",80"
        With .Replacement
            .ClearFormatting
            .Text = ",7"
            .Text = ",8"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = ",90"
        .Text = "É"
        With .Replacement
            .ClearFormatting
            .Text = ",9"
            .Text = "E"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "È"
        .Text = "Ë"
        With .Replacement
            .ClearFormatting
            .Text = "E"
            .Text = "E"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Ê"
        .Text = "À"
        With .Replacement
            .ClearFormatting
            .Text = "E"
            .Text = "A"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Ä"
        .Text = "Â"
        With .Replacement
            .ClearFormatting
            .Text = "A"
            .Text = "A"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Ù"
        .Text = "Ü"
        With .Replacement
            .ClearFormatting
            .Text = "U"
            .Text = "U"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Û"
        .Text = "Ï"
        With .Replacement
            .ClearFormatting
            .Text = "U"
            .Text = "I"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Î"
        .Text = "Ö"
        With .Replacement
            .ClearFormatting
            .Text = "I"
            .Text = "O"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    Set myRange = ActiveDocument.Range(Start:=0, End:=0)
    With myRange.Find
        .ClearFormatting
        .Text = "Ô"
        .Text = "Ç"
        With .Replacement
            .ClearFormatting
            .Text = "O"
            .Text = "C"
        End With
        .Execute Replace:=wdReplaceAll, _
            Format:=True, MatchCase:=True, _
            MatchWholeWord:=True
    End With
     
    End Sub

Discussions similaires

  1. Script pour remplacer une chaine de caractères par une autre
    Par babiêtiguiya dans le forum Scripts/Batch
    Réponses: 0
    Dernier message: 28/02/2012, 14h57
  2. Créer une fonction pour remplacer des caractères
    Par virtuadrack dans le forum C++
    Réponses: 4
    Dernier message: 11/09/2008, 14h52
  3. Réponses: 2
    Dernier message: 22/10/2007, 17h50
  4. [RegEx] Pour remplacer des identifiants de fichiers incorporés par leur valeur
    Par Christophe Charron dans le forum Langage
    Réponses: 12
    Dernier message: 23/08/2007, 08h54
  5. Parser une page pour remplaçer des mots par d'autres
    Par HALOMOTO dans le forum Langage
    Réponses: 13
    Dernier message: 13/07/2006, 22h58

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