View Single Post
 
Old 11-13-2022, 10:33 PM
tanko tanko is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2021
Posts: 17
tanko is on a distinguished road
Default For loop not moving to next paragraph

Hi all.

The code below will just not move on to the next paragraph no matter what I do. It just loops over and over on the same paragraph. What am I missing?

Code:
Private Sub secHeading()
    Dim para As Paragraph
    Dim firstword As String

    For Each para In ActiveDocument.Range.Paragraphs
        If InStr(1, para.Range.Words(1), "RCW") <> 0 Then
            With para.Range
                .Collapse (wdCollapseEnd)
                .Move Unit:=wdCharacter, Count:=-1
                .Delete
                .InsertAfter ("  --  ")
                .Style = "Heading 1"
            End With
        End If
    Next
    
End Sub
Reply With Quote