View Single Post
 
Old 06-19-2018, 11:31 AM
d4okeefe d4okeefe is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

Try this. I prefer to use a for loop (rather than a for each loop) here.
Code:
Sub Rpl()
    Dim lineText As String
    Dim MyPos
    
    Dim x As Integer
    For x = 1 To ActiveDocument.Paragraphs.Count
        lineText = ActiveDocument.Paragraphs(x).Range.Text
        MyPos = InStr(lineText, "Test Text")
        If MyPos = 1 Then
            ActiveDocument.Paragraphs(x).Range.Text = lineText & "LxW "
        End If
    Next x
End Sub
Also, notice that in your original you only change the string -- lineText. The actual paragraph -- singleLine -- is never changed.
Reply With Quote