VB for Word - Need macro to loop each line in a document
Hi All -
I am VERY new to macros in Word. I have written the following macro for Word that will remove line numbers from the start of each line (1 line per paragraph). These line numbers are automatically created in an EDI software that I pull data from and they need to be removed. The macro is removing everything in the line up to the second word (EDI segment). Instead of changing the counter (value currently set at 80) I would like for the macro to run through the entire document. Some of the EDI files that I pull will have +7000 lines and it will get tiresome to have to change this value each time. The rest of the macro is just removing all of the CR so that the data can be shown as a stream. Trust me, I wish everyone used an EDI viewer because this wouldn't be as much of a pain. Please let me know if you have any thoughts.
' EDI fix Macro
'
Dim i As Long
i = 1
Do Until i > 80
Selection.MoveRight Unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
i = i + 1
Loop
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
|