跳到主要內容

 如果他的生日是今天在Outlook中,如何自動向聯繫人發送問候消息?

有時,您可能希望在Outlook的生日今天是該聯繫人的生日時自動向該聯繫人發送問候消息。 當您逐個檢查聯繫人的生日並手動發送問候電子郵件時,這將是一項繁瑣的工作。 本文中,我將介紹一個VBA代碼以快速輕鬆地解決它。

使用Outlook中的VBA代碼根據其生日自動向聯繫人發送問候消息


使用Outlook中的VBA代碼根據其生日自動向聯繫人發送問候消息

要自動向聯繫人發送問候消息(如果他今天是生日),請首先插入VBA代碼,然後您需要創建一個重複任務來觸發該代碼。

以下步驟可以為您提供幫助:

1。 啟動Outlook,然後按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 在 Microsoft Visual Basic for Applications 窗口,雙擊 本次展望會議 來自 Project1(VbaProject.OTM) 窗格以打開模式,然後將以下代碼複製並粘貼到空白模塊中。

VBA代碼:根據生日自動向聯繫人發送問候消息:

Private Sub Application_Reminder(ByVal Item As Object)
Dim xTempMail As MailItem
Dim xFilePath As String
Dim xItems As Outlook.Items
Dim xItem As Object
Dim xContactItem As Outlook.ContactItem
Dim xTodayDate As String
Dim xBirthdayDate As String
Dim xGreetingMail As Outlook.MailItem
Dim xWordDoc As Word.Document
Dim xGreetings As String
Dim xBool As Boolean
xFilePath = CreateObject("shell.Application").NameSpace(5).self.Path & "\UserTemplates"
Set xFSO = CreateObject("Scripting.FileSystemObject")
If xFSO.FolderExists(xFilePath) = False Then
    MkDir xFilePath
End If
If IsFileExists(xFilePath & "\Birthday Greeting Mail.oft") = False Then
    Set xTempMail = Outlook.CreateItem(olMailItem)
    xTempMail.SaveAs xFilePath & "\Birthday Greeting Mail.oft", olTemplate
    xTempMail.Close olDiscard
End If
If (TypeOf Item Is TaskItem) And (Item.Subject = "Send Birthday Greeting Mail") Then
xGreetings = "Happy Birthday!"
           xGreetings = InputBox("Input birthday greetings", "Kutools for Outlook", xGreetings)
   xTodayDate = Month(Date) & "-" & Day(Date)
   Set xItems = Outlook.Application.Session.GetDefaultFolder(olFolderContacts).Items
   For Each xItem In xItems
       If Not (TypeOf xItem Is ContactItem) Then Exit Sub
       Set xContactItem = xItem
       xBirthdayDate = Month(xContactItem.Birthday) & "-" & Day(xContactItem.Birthday)
       If xBirthdayDate = xTodayDate Then
           Set xGreetingMail = Outlook.Application.CreateItemFromTemplate(xFilePath & "\Birthday Greeting Mail.oft")
           Set xWordDoc = xGreetingMail.GetInspector.WordEditor
           
           xWordDoc.Range.InsertBefore "Dear " & xContactItem.LastName & Chr(10) & xGreetings & Chr(10) & Chr(10)
           With xGreetingMail
                .Recipients.Add (xContactItem.Email1Address)
                .Subject = "Happy Birthday!"
                .Display
                .Close (olSave)
                .Send
          End With
       End If
   Next
End If
End Sub
Function IsFileExists(ByVal FileName As String) As Boolean
Dim xFileSystem As Object
Set xFileSystem = CreateObject("Scripting.FileSystemObject")
If xFileSystem.FileExists(FileName) = True Then
    IsFileExists = True
Else
    IsFileExists = False
End If
End Function 

3。 然後點擊 工具 > 參考 ,在 Microsoft Visual Basic for Applications 窗口,彈出 參考-Project1 對話框,檢查 Microsoft Word對像庫Microsoft腳本運行時 來自的選項 可用參考 列錶框,請參見屏幕截圖:

4。 然後點擊 OK 要關閉對話框,現在您應該建立一個任務來觸發 VBA 程式碼。 請前往 任務 窗格中單擊 新任務 建立任務:

(1.)在 主題t 行,您應該輸入主題為 寄送生日祝福郵件;

(2.)然後單擊 循環任務 標籤;

(3.)在 任務重複 對話框中選擇 每日 並指定 每 1 天 選項從 重複模式 部分;

5。 然後點擊 OK 若要關閉對話框,返回任務窗口,請為重複任務設定提醒,如下圖所示:

6。 從現在開始,當提醒發生時,巨集將立即被觸發。 將彈出一個對話框提醒您插入生日祝福,如下圖所示:

7。 然後點擊 OK 按鈕,將自動向今天生日的聯絡人發送問候郵件。


最佳辦公生產力工具

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

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

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

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

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

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

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

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

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

閱讀更多       免費下載      購買
 

 

Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Good morning,
I've set this up exactly as outlined, I have Kutools installed, however, there's no Macro popup when the reminder activates. What information can I provide you to help me solve this?
This comment was minimized by the moderator on the site
how he come to know who's birthday is today.you not mention, from where he pick detail of the employee.one more thing, i want to send birthday mail to all employee email id.
This comment was minimized by the moderator on the site
I am using this code with outlook 2016. Followed all the steps but kutool popup is not coming as mentioned in last step
This comment was minimized by the moderator on the site
hay alguna forma para mac?
This comment was minimized by the moderator on the site
Buen día, podría indicar cómo el código obtiene y valida la fecha de nacimiento??? . Otra consulta es si funciona para una lista de usuarios. Es decir que valide sus fechas de nacimiento y les envíe automáticamente saludos de cumpleaños. Muchas gracias
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations