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 12/07/2007, 07h12   #1
Invité régulier
 
Inscription : juillet 2007
Messages : 34
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 34
Points : 5
Points : 5
Par défaut Supprimer du texte entre 2 caracteres recherchés dans un texte

Bonjour,

Je débute... et je cherche un macro qui :
  • place le point d'insertion au début du document word ;
  • recherche vers le bas du texte en "blue" ;
  • recherche vers le haut le deuxième caractère "{" ;
  • recherche vers le bas le deuxième caractère "}" ;
  • supprime le texte allant du premier "{" au deuxième "}" ;
  • tourne en boucle jusqu'à ce qu'il y ai plus d'occurrence.

Ce que je n'arrive pas a lui faire faire, c'est sélectionner le texte du premier "{" au deuxième "}" inclus et de le supprimer.

Si quelqu'un a une idée, je suis preneur.

Merci d'avance,
Broise
broise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/07/2007, 07h37   #2
Invité régulier
 
Inscription : juillet 2007
Messages : 34
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 34
Points : 5
Points : 5
Par défaut Ca avance... mais besoin d'un petit coup de main

Bonjour,

Ca marche presque.

La macro insere un signet au debut de la chaine de caractere et un autre a la fin et selectionne ce qu'il y a entre les deux signets puis supprime les signets.

Il ne restera qu'a lui demander de supprimer le texte selectionner.

Le pti probleme, c'est qu'en fait, la macro ne selectionne pas tout a fait ce qu'il y a entre les signets meme si ceux ci sont places par la macro comme il faut... enfin, il me semble.

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
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
 
Sub test1()
'
' test1 Macro
' Macro recorded 7/13/2007 by Moi
'
 
'se place au debut du doc et insere les signets
 
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "{"
        .Replacement.Text = ""
        .Forward = False
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="debut"
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "}"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="fin"
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
 
 'Selection de ce qu'il y a entre les signets
 
    Selection.Find.ClearFormatting
    Selection.GoTo What:=wdGoToBookmark, Name:="debut"
    With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.Find.Execute
    Selection.Extend
 
    Selection.Find.ClearFormatting
    Selection.GoTo What:=wdGoToBookmark, Name:="fin"
     With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.Find.Execute
 
 'il faudra ajouter la suppression du texte selecionner
 
'Supprime les signets
 
    ActiveDocument.Bookmarks("debut").Delete
    ActiveDocument.Bookmarks("fin").Delete
    With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
End Sub
broise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/07/2007, 11h28   #3
Membre habitué
 
Inscription : juin 2007
Messages : 175
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 175
Points : 147
Points : 147
J'essaie de nous aider (toi et moi) car je galere aussi dans les macros Word!

J'ai copié ton code et j'ai déjà 2 soucis:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
   Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
wdstory et wdfindask ?

Comment tu les déclares? car Vb me donne des erreus de variables non définies.
COCONUT2 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/07/2007, 11h50   #4
Invité régulier
 
Inscription : juillet 2007
Messages : 34
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 34
Points : 5
Points : 5
Par défaut Hello COCONUT2

Merci de te pencher aussi sur la question.

Il faut les déclarer ?

Il me semble que c'est le placement du point d'insertion au debut du document ca :
Code :
Selection.HomeKey Unit:=wdStory
broise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/07/2007, 12h08   #5
Invité régulier
 
Inscription : juillet 2007
Messages : 34
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 34
Points : 5
Points : 5
Par défaut wdFindAsk

wdFindAsk : quand l’opération de recherche est terminée dans la plage de
celle-ci, une boîte de dialogue demande si la recherche doit continuer
dans le restant du document ;

il faurdait plutot mettre "wdFindStop" :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
pour que la recherche s'arrête juste apres avoir trouver l'occurrence.
broise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/07/2007, 14h46   #6
Membre habitué
 
Inscription : juin 2007
Messages : 175
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 175
Points : 147
Points : 147
C'est aussi ce que je pense: Ce sont des fonctionnalités et non des variables.

Il faut que je réessaie car depuis, j'ai intégré la bibliotheque Word à VB-E

C'est vachement complexe je trouve!
COCONUT2 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h51.


 
 
 
 
Partenaires

Hébergement Web