I'm trying to write a macro to break up a long list of addresses for someone. Basically, the macro needs to add a blank line after every three lines AND repeat this procedure for the entire document. I have gotten the initial action to work, but I can't figure out how to get it to repeat and stop at the end of the document. I've searched online and keep finding while loops that only apply to situations in Excel. I'm not sure how to specify when the loop should end in Word.
Here is what I have right now:
Sub AddFix ()
Do
Selection.MoveDown Unit:= wdline, Count:= 3
Selection.InsertParagraph
Loop Until (Selection.End = ActiveDocument.Content.End - 1)
EndSub
How do I get this sub to work through the whole document?
Building off Chumble's answer, you will want to step backwards through your text.
Sub InsertLines()
Dim lTotalLines As Long
Dim lCurrentLine As Long
lTotalLines = ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)
For lCurrentLine = lTotalLines To 3 Step -3
Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=lCurrentLine
Selection.InsertParagraph
Next lCurrentLine
End Sub
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments