跳到主要内容

 如果他的生日是今天在Outlook中,如何自动向联系人发送问候消息?

有时,您可能希望在Outlook的生日今天是该联系人的生日时自动向该联系人发送问候消息。 当您逐个检查联系人的生日并手动发送问候电子邮件时,这将是一项繁琐的工作。 本文,我将介绍一个VBA代码来快速轻松地解决它。

使用Outlook中的VBA代码根据其生日自动向联系人发送问候消息


使用Outlook中的VBA代码根据其生日自动向联系人发送问候消息

要自动向联系人发送问候消息(如果他今天是生日),请首先插入VBA代码,然后需要创建一个重复任务来触发该代码。

以下步骤可以为您提供帮助:

1。 启动Outlook,然后按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 在 Microsoft Visual Basic应用程序 窗口,双击 本次展望会议 来自 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应用程序 窗口,弹出 参考-Project1 对话框,检查 Microsoft Word对象库Microsoft脚本运行时 来自的选项 可用参考 列表框,请参见屏幕截图:

4。 然后点击 OK 要关闭对话框,现在,您应该创建一个任务以触发VBA代码。 请去 任务 窗格中单击 新任务 创建任务:

(1.)在 主题t行,您应该输入Subject作为 发送生日祝福邮件;

(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