none
vba word - How to move down a line RRS feed

  • Question

  • Hi VBA folks

    I am trying to code a little macro which is giving me a hard time coding it the right way, this are the things I have to do:

    1) Insert a  new section at the end of the document

    2)type the first sentence of each section on separate lines in the newly added section

    for this I pieced together the following code:

    ActiveDocument.Sections.Add Start:=wdSectionNewPage
    
    For Each ss In ActiveDocument.Sections
        ActiveDocument.Sections(ActiveDocument.Sections.count).Range.Text = ss.Range.Sentences(1).Range.Text
       Selection.MoveDown unit:=wdLine, count:=3, Extend:=wdMove
    Next ss
    


    however, it seems like word is just overriding the text on the same line and not moving down a given number of lines to type the next paragraph

    I know that the problem is within the following part, could someone please help me correct this. thanks so much guys

    Selection.MoveDown unit:=wdLine, count:=3, Extend:=wdMove<br/>
    
    Thursday, November 24, 2011 11:53 PM

Answers

  • For these snippets In Word, Excel and Proejct VBA I always record a short macro. It often provides either a line or two of usable code or a great start!

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Friday, November 25, 2011 6:30 AM
  • Use:

    Selection.EndKey wdStory
    Selection.InsertBreak wdSectionBreakNextPage
    With ActiveDocument
        With .Sections(.Sections.Count).Range
            For i = 1 To ActiveDocument.Sections.Count - 1
                .InsertAfter ActiveDocument.Sections(i).Range.Sentences(1).Text & vbCr
            Next i
        End With
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, November 26, 2011 5:29 AM

All replies

  • For these snippets In Word, Excel and Proejct VBA I always record a short macro. It often provides either a line or two of usable code or a great start!

    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Friday, November 25, 2011 6:30 AM
  • Use:

    Selection.EndKey wdStory
    Selection.InsertBreak wdSectionBreakNextPage
    With ActiveDocument
        With .Sections(.Sections.Count).Range
            For i = 1 To ActiveDocument.Sections.Count - 1
                .InsertAfter ActiveDocument.Sections(i).Range.Sentences(1).Text & vbCr
            Next i
        End With
    End With


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, November 26, 2011 5:29 AM