Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/04/2007, 11h46   #1
Invité de passage
 
Inscription : avril 2007
Messages : 2
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 2
Points : 1
Points : 1
Par défaut [VBA-W] comment supprimer un paragraphe délimité par un mot précis ?

Bonjour,

J'ai un document word générer automatiquement par un publipostage qui contient des paragraphes vides délimités par des mots précis (ici toto).

Exemple :

6.31. toto


toto
6.32. Transfert (aller simple)

En cas de,


6.33. toto


toto

Je souhaite, à l'aide d'une macro vba, supprimer tous les paragraphes commencant par "toto" et finissant par "toto".

J'ai cherché et trouver plusieurs sources sur le net mais aucune ne repond à mes attentes.

Est ce que quelqu'un a une idée ?

Merci d'avance
damienea est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/04/2007, 19h40   #2
Membre éclairé
 
Inscription : octobre 2006
Messages : 390
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 390
Points : 396
Points : 396
Essaie :
Code :
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
Sub Macro1()
    Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "toto" 'texte delimitant la plage
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    deb = -1
    Do While Selection.Find.Execute
        If deb = -1 Then
            deb = Selection.Range.Start
        Else
            ThisDocument.Range(deb, Selection.Range.End).Delete
            deb = -1
        End If
    Loop
End Sub
dadavyvy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/05/2007, 10h25   #3
Invité de passage
 
Inscription : avril 2007
Messages : 2
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 2
Points : 1
Points : 1
Par défaut re

Bonjour,

Merci de t'être penché sur mon problème...

En fait je n'arrivait pas à faire fonctionner ta macro, donc j'ai continué à chercher de mon coté et j'ai enfin trouvé mon bonheur. Je met la macro au cas ou ca puisse interresser d'autres utilisateurs :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
Sub testpara()
 
Dim Para As Paragraph, a
ActiveDocument.Select
For Each Para In ActiveDocument.Paragraphs
Para.Range.Select
a = Trim(Para.Range.Words(1))
If LCase(Trim(Para.Range.Words(1))) = LCase("toto") Then
Para.Range.Delete
End If
 
Next Para
End Sub
damienea est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 13h57.


 
 
 
 
Partenaires

Hébergement Web