許多用戶都渴望有一種方法,可以從Outlook電子郵件的主體甚至是多封電子郵件中快速提取所有電子郵件地址。 因此,本文將著眼於此問題,並與您分享一種使用VBA的快速方法。
當某人向您發送一封電子郵件,其中的郵件正文包含一個電子郵件地址列表時,如果您出於某些原因要使用這些電子郵件地址,例如添加到“聯繫人”文件夾或其他文件夾中,則必須首先提取該郵件正文中的所有電子郵件地址。 因此,在下文中,我們將向您展示如何使用VBA實現它。
從多個Outlook電子郵件的正文中提取所有電子郵件地址
- 首先,啟動Outlook應用程序。
- 然後,進入Outlook主窗口後,可以按“ Alt + F11”鍵。
- 接下來,在新的“ Microsoft Visual Basic for Applications”窗口中,您需要打開一個未使用的模塊或簡單地插入一個新模塊。
- 以後,您必須將以下VBA代碼複製並粘貼到該模塊中。
Sub ExtractEmailAddresses_BodyofMultipleEmails()
Dim objSelection As Outlook.Selection
Dim objMail As Outlook.MailItem
Dim i, n As Long
Dim objWordApp As Word.Application
Dim objWordDocument As Word.Document
Dim strEmailAddresses As String
Dim objFileSystem As Object
Dim strTextFile As String
Dim objTextFile As Object
Set objSelection = Outlook.Application.ActiveExplorer.Selection
If Not (objSelection Is Nothing) Then
i = 0
n = 1
On Error Resume Next
For i = objSelection.count To 1 Step -1
Set objMail = objSelection.Item(i)
objMail.Display
Set objWordDocument = objMail.GetInspector.WordEditor
Set objWordApp = objWordDocument.Application
Set objSearchRange = objWordDocument.Range
'Find the email addresses via wildcards
With objWordApp.Selection.Find
.Text = "[A-z,0-9]{1,}\@[A-z,0-9,.]{1,}"
.MatchWildcards = True
.Execute
End With
While objWordApp.Selection.Find.Found
'Get a list of email addresses in the body
strEmailAddresses = strEmailAddresses & n & ": " & objWordApp.Selection.Text & vbCrLf
objWordApp.Selection.Find.Execute
n = n + 1
Wend
objMail.Close olDiscard
Next
End If
'Create a new Text file
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
strTextFile = "E:\Extracted Email Addresses-" & Format(Date, "YYYYMMDD") & ".txt"
Set objTextFile = objFileSystem.CreateTextFile(strTextFile, True)
'Input the list of extracted email addresses into this Text file
objTextFile.WriteLine (strEmailAddresses)
objTextFile.Close
MsgBox "Completed!", vbInformation, "Extract Email Addresses"
End Sub
- 稍後,您可以退出當前的VBA編輯器窗口,並繼續將新的宏添加到快速訪問工具欄。
- 之後,您必須將Outlook宏安全級別更改為低。
- 最後,您可以嘗試一下。
- 首先,在電子郵件列表中,選擇多個Outlook電子郵件,您需要從其中提取電子郵件地址。
- 然後在快速訪問工具欄中單擊新按鈕。
- 當收到提示您“已完成”的消息時,可以轉到VBA代碼中的預定義文件夾以查找新的.TXT文件。
- 打開此文件,您將看到所有提取的電子郵件地址,如以下屏幕截圖所示:
保護Outlook免受惡意宏的侵害
如果將Outlook設置為允許所有宏,則必須注意未知電子郵件中偽裝的所有宏。 這是因為它們可能包含許多隱藏的病毒,這些病毒可能直接導致Outlook損壞。 感染了病毒的PST文件很難恢復。 那時,也許您的最後選擇是有效而可靠的 Outlook修復 實用程序,例如 DataNumen Outlook Repair。 無論損壞有多嚴重,它都可以修復Outlook文件。
作者簡介:
Shirley Zhang是的數據恢復專家 DataNumen,Inc.是數據恢復技術的全球領導者,包括 損壞的SQL 和Outlook修復軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM



