Deprecated: RegularLabs\Library\ArrayHelper::implode(): Implicitly marking parameter $last_glue as nullable is deprecated, the explicit nullable type must be used instead in /homepages/10/d550841420/htdocs/libraries/regularlabs/src/ArrayHelper.php on line 225
Comment remplacer un mot par un autre dans un grand nombre de documents ?

Recherche

 

Voici une macro permettant de remplacer un mot par un autre (ici "premier texte" remplacé par "deuxième texte") dans une série de documents d’un meme dossier.

 

Public Sub RemplacementGlobal()
Dim MonDocument
Dim MonRepertoire
Dim NbDocuments As Integer
MonRepertoire = Options.DefaultFilePath(wdDocumentsPath)
'Attention sous NT, il faut rajouter ces lignes qui comptent les fichiers sinon on ouvre et transforme en boucle :
MonDocument = Dir(MonRepertoire & "*.doc")
While MonDocument <> ""
NbDocuments = NbDocuments + 1
MonDocument = Dir
Wend
'fin du comptage sous NT
MonDocument = Dir(MonRepertoire & "*.doc")
= 1
While MonDocument <> "" And i <= NbDocuments
= i + 1
Documents.Open (MonRepertoire & "" & MonDocument)
ActiveWindow.View.ShowFieldCodes = True
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Set myRange = ActiveDocument.Content
With myRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "premier texte"
.Replacement.Text = "deuxième texte"
.Execute Replace:=wdReplaceAll ' peut être la raison
End With
Selection.Fields.Update
Documents(1).Close wdSaveChanges
MonDocument = Dir
Wend
End Sub

 

NB : Si le texte à remplacer se trouve dans les pieds de page, à la place d'un simple

Set myRange = ActiveDocument.Content

Il faudra mettre :

For each S in ActiveDocument.Sections
For each F in S.Footers
Set myRange = F.Range
'----ici les opérations de recherche-remplacement
Next F
Next

Statistiques

France 72,3% France
Canada 5,3% Canada
Chine 3,7% Chine

Total:

154

Pays
018457934
Aujourd'hui: 119
Hier: 236
Cette semaine: 119
Semaine dernière: 2.729
Ce mois: 5.862