Bonjour,
Sur un code vba sur excel, j'exporte des données. Pour une partie de celle ci je fais un remplacement d'un champs par un autre (ici "TLM" en ma_variable).
Une des pages qui receptionne ce code possède plusieurs sections, et du coup, pour une raison que je ne comprend pas, le code remplace plusieurs fois le résultats, je me retrouve avec deux fois ma variable écrite.
voici ma procedure de remplacement de texte :
Avez vous un idée pour m'aider à résoudre ce soucis ?
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 Sub remplacer(ByRef doc As Word.Document, ByRef recherche As String, ByVal remplace As String) doc.Content.Select Set myrange = doc.Content myrange.Find.Execute FindText:=recherche, ReplaceWith:=remplace, _ Replace:=wdReplaceAll If doc.Shapes.Count > 0 Then For Each sh In doc.Shapes If InStr(sh.Name, "Text") Then Set myrange = sh.TextFrame.TextRange myrange.Find.Execute FindText:=recherche, ReplaceWith:=remplace, _ Replace:=wdReplaceAll End If Next End If Dim sec As Section Dim nombrePage As Integer nombrePage = 0 For Each sec In doc.Sections If nombrePage = 0 Or nombrePage <> sec.Range.Information(3) Then Set myrange = sec.Headers(wdHeaderFooterPrimary).Range myrange.Find.Execute FindText:=recherche, ReplaceWith:=remplace, _ Replace:=wdReplaceAll Set myrange = sec.Footers(wdHeaderFooterPrimary).Range myrange.Find.Execute FindText:=recherche, ReplaceWith:=remplace, _ Replace:=wdReplaceAll nombrePage = sec.Range.Information(3) End If Next End Sub
Partager