View Single Post
 
Old 06-19-2018, 09:28 AM
moorea21 moorea21 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2018
Posts: 8
moorea21 is on a distinguished road
Default Macro to append text to end of paragraphs/lines where target text is found.

Hi,


I am trying to use this code:-


Sub Rpl()
Dim singleLine As Paragraph
Dim lineText As String
Dim MyPos

For Each singleLine In ActiveDocument.Paragraphs
lineText = singleLine.Range.Text

MyPos = InStr(lineText, "Test Text")
'If MyPos = 1 Then Replace(lineText , lineText & "LxW ")
If MyPos = 1 Then lineText = lineText & "LxW "
Next singleLine
End Sub


Although the value of 'lineText' gets updated, it doesn't replace it in the document, so I tried a VB6 'replace' function, which is invalid. How would I get the new value of lineText to replace the old value in the document?


Thanks
Reply With Quote