So I have been using code from How can I copy one section of text from Word to Excel using an Excel macro? to copy certain found text into Word. However, I now need to copy text for a certain number of characters AFTER the found string. Here is the code so far:
Sub FindAndCopyNext()
Dim TextToFind As String, TheContent As String
Dim rng As Word.Range
TextToFind = "Delivery has failed" 'Not sure if this is best string option
Set rng = wdApp.ActiveDocument.Content
rng.Find.Execute FindText:=TextToFind, Forward:=True
If rng.Find.Found Then
'Need to return text (TheContent) that follow the found text
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & LastRow).Value = TheContent
Else
MsgBox "Text '" & TextToFind & "' was not found!"
End If
End Sub
The text in the Word document always looks like this:
'Jibberish Code
<p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p>
<font color="#000000" size="2" face="Tahoma"><p><a href="mailto:[email protected]">[email protected]</a><br>
'Jibberish Code
<p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p>
<font color="#000000" size="2" face="Tahoma"><p><a href="mailto:[email protected]">[email protected]</a><br>
'Jibberish Code
<p><b><font color="#000066" size="3" face="Arial">Delivery has failed to these recipients or groups:</font></b></p>
<font color="#000000" size="2" face="Tahoma"><p><a href="mailto:[email protected]">[email protected]</a><br>
I need just the [email protected]
, each time that string is found, to paste into Excel.