Consulting

Results 1 to 3 of 3

Thread: Add a new paragraph after for each selected paragraph

  1. #1

    Add a new paragraph after for each selected paragraph

    Hi,

    Suppose there are 3 paragraphs:

    *********
    ******
    ******************

    After highlighting them, the VBA would return :

    *********

    ******

    ******************

    Below is my attempted code, but it returns infinite parapraphs.

    Private Sub cmdLnBr_Click()    
    Dim P As Paragraph
        Application.ScreenUpdating = False
        For Each P In Selection.Paragraphs
            P.Range.InsertParagraphAfter
        Next
        Unload Me
    
    End Sub
    How should I amend it?
    Thanks.

  2. #2
    It would make far more sense to add spacing to the paragraphs than to add empty paragraphs.
    Selection.ParagraphFormat.SpaceAfter = 12
    Or better still create a paragraph style in the template/document with the spacing you require and apply it to the selection. e.g.
    Selection.Style = "Stylename"
    Empty paragraphs are used by typewriters. Wordprocessors use spacing which makes subsequent editing far more simple. However if you insist
    Dim lngPara As Long
        For lngPara = Selection.Paragraphs.Count To 1 Step -1
            Selection.Paragraphs(lngPara).Range.InsertParagraphAfter
        Next lngPara
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Quote Originally Posted by gmayor View Post
    It would make far more sense to add spacing to the paragraphs than to add empty paragraphs.
    Selection.ParagraphFormat.SpaceAfter = 12
    Or better still create a paragraph style in the template/document with the spacing you require and apply it to the selection. e.g.
    Selection.Style = "Stylename"
    Empty paragraphs are used by typewriters. Wordprocessors use spacing which makes subsequent editing far more simple. However if you insist
    Dim lngPara As Long
        For lngPara = Selection.Paragraphs.Count To 1 Step -1
            Selection.Paragraphs(lngPara).Range.InsertParagraphAfter
        Next lngPara
    Thank you gmayor!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •