Hi,

I’d like to make macros in Word, in order to automatically delete things or to automatically move paragraphs (that start with the same strings of characters).

I created a macro with the recorder of Word (I don’t know how to write codes in Visual Basic, I know nothing about VB actually). The problem is that I don’t know how to make a loop so that the task is done on every paragraph until the end of the document. It stops at the end of the first paragraph.
I think I have to write « loop » somewhere, but I don’t know where, and I don’t know what else I should write in the macro.
Could someone help me please ? Thanks a lot in advance.

Here is the code I’ve got so far :
I’d like to make macros in Word, in order to automatically delete things or to automatically move paragraphs (that start with the same strings of characters).

I created a macro with the recorder of Word (I don’t know how to write codes in Visual Basic, I know nothing about VB actually). The problem is that I don’t know how to make a loop so that the task is done on every paragraph until the end of the document. It stops at the end of the first paragraph.
I think I have to write « loop » somewhere, but I don’t know where, and I don’t know what else I should write in the macro.
Could someone help me please ? Thanks a lot in advance.

Here is the code I’ve got so far :





Sub XmlToLpEffacerChampsInutiles()
'' XmlToLpEffacerChampsInutiles Macro
' Macro enregistrée le 09/11/2013 par Pwyll'    
Selection.Find.ClearFormatting    
With Selection.Find        
.Text = "<identifiant>"        
.Replacement.Text = ""        
.Forward = True        
.Wrap = wdFindContinue        
.Format = False        
.MatchCase = False        
.MatchWholeWord = False        
.MatchWildcards = False        
.MatchSoundsLike = False        
.MatchAllWordForms = False    
End With    
Selection.Find.Execute    
Selection.MoveLeft Unit:=wdCharacter, Count:=1    
Selection.MoveDown Unit:=wdParagraph, Count:=1,  Extend:=wdExtend    
Selection.TypeBackspace    
Selection.Find.ClearFormatting    
With Selection.Find        
.Text = "<image>"        
.Replacement.Text = ""        
.Forward = True        
.Wrap = wdFindContinue        
.Format = False        
.MatchCase = False        
.MatchWholeWord = False        
.MatchWildcards = False        
.MatchSoundsLike = False        
.MatchAllWordForms = False    
End With    
Selection.Find.Execute    
Selection.MoveLeft Unit:=wdCharacter, Count:=1    
Selection.MoveDown Unit:=wdParagraph, Count:=3,  Extend:=wdExtend    
Selection.TypeBackspace    
Selection.Find.ClearFormatting    
With Selection.Find        
.Text = "<enqueteur>"        
.Replacement.Text = ""        
.Forward = True        
.Wrap = wdFindContinue        
.Format = False        
.MatchCase = False        
.MatchWholeWord = False        
.MatchWildcards = False        
.MatchSoundsLike = False        
.MatchAllWordForms = False    
End With    
Selection.Find.Execute    
Selection.MoveLeft Unit:=wdCharacter, Count:=1    
Selection.MoveDown Unit:=wdParagraph, Count:=11,  Extend:=wdExtend    
Selection.TypeBackspace    
Selection.Find.ClearFormatting    
With Selection.Find        
.Text = "<DonneesMorpho>"        
.Replacement.Text = ""        
.Forward = True        
.Wrap = wdFindContinue        
.Format = False        
.MatchCase = False        
.MatchWholeWord = False        
.MatchWildcards = False        
.MatchSoundsLike = False        
.MatchAllWordForms = False    
End With    
Selection.Find.Execute    
Selection.MoveLeft Unit:=wdCharacter, Count:=1    
Selection.MoveDown Unit:=wdParagraph, Count:=2,  Extend:=wdExtend    
Selection.TypeBackspace    
Selection.Find.ClearFormatting    
With Selection.Find        
.Text = "<type>"        
.Replacement.Text = ""        
.Forward = True        
.Wrap = wdFindContinue        
.Format = False        
.MatchCase = False        
.MatchWholeWord = False        
.MatchWildcards = False        
.MatchSoundsLike = False        
.MatchAllWordForms = False    
End With    Selection.Find.Execute    
Selection.MoveLeft Unit:=wdCharacter, Count:=1    
Selection.MoveDown Unit:=wdParagraph, Count:=9,  Extend:=wdExtend    
Selection.TypeBackspace
End Sub