因此,我一直在使用How can I copy one section of text from Word to Excel using an Excel macro?中的代碼將某些找到的文本複製到Word中。但是,我現在需要在找到的字符串之後複製文本中的一定數量的字符。這是迄今爲止代碼:找到從Word到Excel文本後的文本複製
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
在Word文檔中的文本始終是這樣的:
'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>
我需要的只是[email protected]
,每個串中發現的時間,將其粘貼到Excel中。
我從來沒有使用RegEx搜索,但它似乎只適用於一個電子郵件。我需要它循環瀏覽所有電子郵件並跳到每一行的新行(根據我在Q中的代碼) – Chrismas007 2015-02-05 17:06:11
我已經更新了我的答案以解決您的評論。 – Jeanno 2015-02-05 17:33:28