Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-19-2018, 11:31 AM
d4okeefe d4okeefe is offline Macro to append text to end of paragraphs/lines where target text is found. Windows 10 Macro to append text to end of paragraphs/lines where target text is found. 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
 

Tags
append, replace, vb6



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to append text to end of paragraphs/lines where target text is found. Macro to hide all paragraphs that do not have the found result jplat Word VBA 1 09-10-2017 09:13 PM
Delete Text from Insertion Point to Found Text feenyman99 Word 0 04-17-2016 05:40 PM
Macro to append text to end of paragraphs/lines where target text is found. Macro to color row of Word table based on found text kristib Word VBA 4 11-15-2015 02:42 PM
Macro to append text to end of paragraphs/lines where target text is found. Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank caboy Word VBA 2 04-01-2015 07:00 AM
Macro to Insert Text Into Cells Having Multiple Lines revans611 Excel Programming 4 10-24-2011 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft