跳到主要內容

通過Outlook發送之前如何檢查收件人地址?

在某些時候,您可能會錯過通過Outlook發送電子郵件時將一些重要的收件人添加到“收件人”,“抄送”或“密件抄送”字段中的情況。 在這裡,我可以介紹一種在通過Outlook發送之前檢查是否已添加特定電子郵件地址的方法。

使用VBA代碼發送前檢查地址


使用VBA代碼發送前檢查地址

在這裡,我有兩個代碼可以幫助您解決此工作,您可以根據需要選擇任何人。

1。 按 Alt + F11 k啟用 Microsoft Visual Basic for Applications 窗口。

2。 雙擊 本次展望會議 Project1 窗格以打開代碼編輯器,將下面的代碼複製並粘貼到編輯器中。

VBA:發送前在“收件人”字段中檢查收件人地址

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'UpdatebyExtendoffice20180523
Dim xAddressArr() As Variant
Dim xAddress As String
Dim xRecipient As Recipient
Dim xPrompt As String
Dim xYesNo As Integer
Dim xDictionary As Scripting.Dictionary
On Error Resume Next
Set xDictionary = New Scripting.Dictionary
xAddressArr = Array("", "", "")
For i = LBound(xAddressArr) To UBound(xAddressArr)
    xDictionary.Add xAddressArr(i), True
Next i
For Each xRecipient In Item.Recipients
    If xRecipient.Type = olTo Then
        If xDictionary.Exists(xRecipient.Address) Then xDictionary.Remove xRecipient.Address
    End If
Next
If xDictionary.Count = 0 Then GoTo L1
For i = 0 To xDictionary.Count - 1
    If xAddress = "" Then
        xAddress = xDictionary.Keys(i)
    Else
        xAddress = xAddress + "; " & xDictionary.Keys(i)
    End If
Next i
xPrompt = "You are not sending this to: " & xAddress & ". Are you sure you want to send the Mail?"
xYesNo = MsgBox(xPrompt, vbQuestion + vbYesNo, "Kutools for Outlook")
If xYesNo = vbNo Then Cancel = True
L1:
  Set xRecipient = Nothing
  Set xDictionary = Nothing
End Sub

doc在發送1之前檢查收件人地址

在代碼中,您可以更改 ("“”“”") 給您所需的真實收件人。

3.然後在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考。 檢查 Microsoft腳本運行時 複選框 參考-Project1 對話。

doc在發送2之前檢查收件人地址 doc箭頭向右 doc在發送3之前檢查收件人地址

4。 點擊 OK 並保存代碼。

現在,如果在發送電子郵件時指定的收件人沒有出現在“收件人”字段中,則會彈出一個對話框,提醒您是否發送電子郵件。
doc在發送4之前檢查收件人地址

使用上面的代碼,它僅檢查以下位置的電子郵件地址 字段,如果您想簽入 , CCBCC 字段,您可以使用以下代碼。

VBA:發送前在“收件人/抄送/密件抄送”字段中檢查收件人地址

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'UpdatebyExtendoffice20180523
Dim xRecipients As Outlook.Recipients
Dim xRecipient As Outlook.Recipient
Dim xPos As Integer
Dim xYesNo As Integer
Dim xPrompt As String
Dim xAddress As String
On Error Resume Next
If Item.Class <> olMail Then Exit Sub
Set xRecipients = Item.Recipients
xAddress = ""
For Each xRecipient In xRecipients
    xPos = InStr(LCase(xRecipient.Address), xAddress)
    If xPos = 0 Then
        xPrompt = "You sending this to " & xAddress & ". Are you sure you want to send it?"
        xYesNo = MsgBox(xPrompt, vbYesNo + vbQuestion + 4096, "Kutools for Outlook")
        If xYesNo = vbNo Then Cancel = True
    End If
Next xRecipient
End Sub

使用此代碼,您無需檢查 Microsoft腳本運行時 複選框,只需直接保存代碼即可生效。


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations