Loop to add blank lines that repeats until end of the Word document

Peckish

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?

Chrismas007

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Loop until end of document

From Java

Apache Poi - Java-: How to add text containing blank lines as separate paragraphs to a Word document using Apache POI?

From Dev

Add word at the end of lines in file by groovy

From Dev

.NET Regex Add Character to End of Non-Blank Lines

From Dev

Loop through a row until blank

From Dev

Removing blank lines in the xml document

From Dev

RegExp match until end of word

From Dev

Loop down column until blank cell

From Dev

Python - delete blank lines of text at the end of the file

From Dev

Microsoft Word: delete blank lines or empty paragraphs

From Dev

Match blank lines before a word awk

From Dev

dompdf inserts blank page at end of document

From Dev

Java Loop Until add elements

From Dev

Loop through several lines until a condition is reached

From Dev

Loop through several lines until a condition is reached

From Dev

Reading text file and skipping blank lines until EOF is reached

From Dev

Delete unknown number of lines from * until blank line

From Dev

Remove lines after match, until blank line occurs

From Dev

Delete lines following the search pattern until blank line

From Dev

Loop through each word in a word document

From Dev

phantom js not injecting javascript until end of loop

From Dev

Iterate in Python with a loop until the end of the list is reached

From Dev

Bash CRLF - new lines at the end of document

From Dev

Removing lines in text document that end the same

From Dev

Bash CRLF - new lines at the end of document

From Dev

Word 2010: Add document as appendix to another document

From Dev

Check Word Document Style for every single lines

From Dev

Scala - Filter lines in a document if a string/word is present

From Dev

How to add blank lines above the bottom in terminal

Related Related

  1. 1

    Loop until end of document

  2. 2

    Apache Poi - Java-: How to add text containing blank lines as separate paragraphs to a Word document using Apache POI?

  3. 3

    Add word at the end of lines in file by groovy

  4. 4

    .NET Regex Add Character to End of Non-Blank Lines

  5. 5

    Loop through a row until blank

  6. 6

    Removing blank lines in the xml document

  7. 7

    RegExp match until end of word

  8. 8

    Loop down column until blank cell

  9. 9

    Python - delete blank lines of text at the end of the file

  10. 10

    Microsoft Word: delete blank lines or empty paragraphs

  11. 11

    Match blank lines before a word awk

  12. 12

    dompdf inserts blank page at end of document

  13. 13

    Java Loop Until add elements

  14. 14

    Loop through several lines until a condition is reached

  15. 15

    Loop through several lines until a condition is reached

  16. 16

    Reading text file and skipping blank lines until EOF is reached

  17. 17

    Delete unknown number of lines from * until blank line

  18. 18

    Remove lines after match, until blank line occurs

  19. 19

    Delete lines following the search pattern until blank line

  20. 20

    Loop through each word in a word document

  21. 21

    phantom js not injecting javascript until end of loop

  22. 22

    Iterate in Python with a loop until the end of the list is reached

  23. 23

    Bash CRLF - new lines at the end of document

  24. 24

    Removing lines in text document that end the same

  25. 25

    Bash CRLF - new lines at the end of document

  26. 26

    Word 2010: Add document as appendix to another document

  27. 27

    Check Word Document Style for every single lines

  28. 28

    Scala - Filter lines in a document if a string/word is present

  29. 29

    How to add blank lines above the bottom in terminal

HotTag

Archive