Skip to main content

如何在 Outlook 中根據特定域名導出郵件地址?

Author: Xiaoyang Last Modified: 2025-05-12

如果您想從 Outlook 的所有聯絡人中導出具有特定域名的郵件地址,請閱讀本教程,它將幫助您應用 VBA 代碼來提取特定域名的所有郵件地址到文本文件中,如下方截圖所示。

doc-export-addresses-with-domain-1


使用 VBA 代碼在 Outlook 中根據特定域名導出郵件地址

要從所有聯絡人中提取具有特定域名的所有郵件地址,請按照以下步驟操作:

1. 創建一個新的文本文件並為其命名,參見截圖:

doc-export-addresses-with-domain-2

2. 按住「ALT + F11」鍵打開「Microsoft Visual Basic for Applications」窗口。

3. 然後,點擊「插入」>「模塊」,並將以下代碼粘貼到模塊窗口中。

「VBA 代碼:根據特定域名導出郵件地址」

Dim GDomain As String
Dim GFileSystem As Object
Dim GFilePath As String
Dim GFileObj As Object
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, _
  ByVal ipOperation As String, ByVal lpFile As String, _
  ByVal lpParameters As String, ByVal lpDirectory As String, _
  ByVal nShowCmd As Long) As Long

Sub ExportListOfEmailAddressesInSpecificDomain()
'Updateby ExtendOffice
Dim xStore As Store
Dim xFolder As Folder
On Error Resume Next
GDomain = InputBox("Enter domain(@***.com):", "Kutools for Outlook")
If Len(GDomain) <> 0 Then
  GFilePath = "C:\Users\skyyang\Desktop\Email Addresses with specific domain.txt" 'Specify the file path
  Set GFileSystem = CreateObject("Scripting.FileSystemObject")
  Set GFileObj = GFileSystem.CreateTextFile(GFilePath, True)
  For Each xStore In Application.Session.Stores
    For Each xFolder In xStore.GetRootFolder.Folders
      If xFolder.DefaultItemType = olContactItem Then
        Call ProcessFolders(xFolder)
      End If
    Next
  Next
  GFileObj.Close
  ShellExecute 0&, vbNullString, GFilePath, vbNullString, vbNullString, 1
End If
End Sub

Sub ProcessFolders(ByVal Fld As Outlook.Folder)
Dim xContactItems As Items
Dim I As Long
Dim xContact As ContactItem
Dim xSubFolder As Folder
On Error Resume Next
Set xContactItems = Fld.Items
For I = xContactItems.Count To 1 Step -1
  If xContactItems(I).Class = olContact Then
    Set xContact = xContactItems(I)
    If InStr(xContact.Email1Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email1Address & vbCrLf)
    ElseIf InStr(xContact.Email2Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email2Address & vbCrLf)
    ElseIf InStr(xContact.Email3Address, GDomain) > 0 Then
      GFileObj.WriteLine (xContact.Email3Address & vbCrLf)
    End If
  End If
Next
If Fld.Folders.Count > 0 Then
  For Each xSubFolder In Fld.Folders
    If xSubFolder.DefaultItemType = olContactItem Then
      Call ProcessFolders(xSubFolder)
    End If
  Next
End If
End Sub
注意:在上述代碼中,將文件路徑「C:\Users\skyyang\Desktop\Email Addresses with specific domain.txt」更改為您自己的路徑。

doc-export-addresses-with-domain-4

4. 然後,按「F5」鍵運行此代碼。會彈出一個提示框,請輸入您想根據其導出郵件地址的郵箱域名,參見截圖:

doc-export-addresses-with-domain-3

5. 接著,點擊「確定」按鈕,特定域名中的所有郵件地址將立即被提取到文本文件中,參見截圖:

doc-export-addresses-with-domain-1

Outlook中的AI郵件助理:更聰明的回覆,更清晰的溝通(一鍵奇蹟!) 免費

使用Kutools for Outlook的AI郵件助理簡化您的日常Outlook任務。這個強大的工具會從您過去的郵件中學習,提供智能且準確的答覆,優化您的郵件內容,並幫助您輕鬆起草和潤色郵件。
doc ai email handle

此功能支援:

  • 智能回覆:根據您過去的對話獲得量身定制、精確且隨時可用的回覆。
  • 增強內容:自動優化您的郵件文字以提高清晰度和影響力。
  • 輕鬆撰寫:只需提供關鍵字,讓AI處理其餘部分,並有多種寫作風格可供選擇。
  • 智能擴展:通過上下文感知建議來拓展您的思路。
  • 摘要生成:即時獲取長郵件的簡潔概述。
  • 全球觸及:輕鬆將您的郵件翻譯成任何語言。

此功能支援:

  • 智能郵件回覆
  • 優化的內容
  • 基於關鍵字的草稿
  • 智能內容擴展
  • 郵件摘要生成
  • 多語言翻譯

最重要的是,此功能永遠完全免費不要再等待了——立即下載AI郵件助理並享受吧