跳到主要内容

在Outlook中回复邮件时如何自动创建亲爱的发件人姓名?

回复电子邮件时,您应该手动键入发件人的姓名和问候。 为了节省时间并提高工作效率,您可以考虑在Outlook中自动创建亲爱的发件人的姓名和问候。 本文,我将讨论一些解决Outlook中此任务的有用方法。

使用VBA代码回复邮件时,自动创建亲爱的发件人姓名和问候语

使用 Kutools for Outlook 回复消息时自动创建亲爱的发件人的姓名和问候语


使用VBA代码回复邮件时,自动创建亲爱的发件人姓名和问候语

以下VBA代码可以帮助您在回复电子邮件时自动插入亲爱的发件人的姓名和问候语,请按照以下步骤操作:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 在 Microsoft Visual Basic应用程序 窗口,双击 本次展望会议 来自 Project1(VbaProject.OTM) 窗格以打开模式,然后将以下代码复制并粘贴到空白模块中。

VBA代码:回复时自动插入亲爱的发件人的名字和问候:

Public WithEvents GExplorer As Outlook.Explorer
Public WithEvents GMailItem As Outlook.MailItem
Private Sub Application_Startup()
    Set GExplorer = Outlook.Application.ActiveExplorer
End Sub
Private Sub GExplorer_SelectionChange()
    Dim xItem As Object
    On Error Resume Next
    Set xItem = GExplorer.Selection.Item(1)
    If xItem.Class <> olMail Then Exit Sub
    Set GMailItem = xItem
End Sub
Private Sub GMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
    AutoAddGreetingToReply Response
End Sub
Private Sub GMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    AutoAddGreetingToReply Response
End Sub
Sub AutoAddGreetingToReply(Item As Object)
    Dim xGreetStr As String
    Dim xReplyMail As MailItem
    Dim xSenderName As String
    Dim xRecipient As Recipient
    On Error Resume Next
    If Item.Class <> olMail Then Exit Sub
    Set xReplyMail = Item
    For Each xRecipient In xReplyMail.Recipients
        If xSenderName = "" Then
            xSenderName = xRecipient.Name
        Else
            xSenderName = xSenderName & "," & xRecipient.Name
        End If
    Next xRecipient
    Select Case Time
           Case 0.3 To 0.5
                xGreetStr = " Good morning!"
           Case 0.5 To 0.75
                xGreetStr = " Good afternoon!"
           Case Else
                xGreetStr = " Good evening!"
    End Select
    With xReplyMail
        .Display
        .HTMLBody = "<HTML><Body>Dear " & xSenderName & ",</HTML></Body>" & xGreetStr & .HTMLBody
    End With
End Sub

doc自动亲爱的发件人名称1

3. 然后关闭Outlook并重新启动它以使代码生效,现在,当您回复电子邮件时,将自动将亲爱的发件人的姓名和问候插入到正文中,请参见屏幕截图:

doc自动亲爱的发件人名称2


使用 Kutools for Outlook 回复消息时自动创建亲爱的发件人的姓名和问候语

如果你有 Kutools for Outlook,其 回复时添加问候语 功能,Outlook在回复时会自动插入发件人的姓名。

Kutools for Outlook : 带有超过100个方便的Outlook加载项,可以在60天内免费试用. 

安装后 Kutools for Outlook,请这样做:

1。 点击 库工具 > 附加选项,请参见屏幕截图:

doc自动亲爱的发件人名称3

2。 在 附加选项 对话框中的 回复 选项卡,检查 回复时添加问候语 选项,然后根据需要输入问候语,请参见屏幕截图:

doc自动亲爱的发件人名称4

3。 然后点击 OK 为了完成此设置,从现在开始,当回复消息时,问候语将在消息正文之前自动创建,请参见屏幕截图:

doc自动亲爱的发件人名称5

点击下载 Kutools for Outlook 并立即免费试用!


最佳办公生产力工具

Kutools for Outlook - 超过 100 种强大功能可增强您的 Outlook

🤖 人工智能邮件助手: 具有人工智能魔力的即时专业电子邮件——一键天才回复、完美语气、多语言掌握。轻松改变电子邮件! ...

📧 电子邮件自动化: 外出(适用于 POP 和 IMAP)  /  安排发送电子邮件  /  发送电子邮件时按规则自动抄送/密件抄送  /  自动转发(高级规则)   /  自动添加问候语   /  自动将多收件人电子邮件拆分为单独的消息 ...

📨 电子邮件管理: 轻松回忆电子邮件  /  按主题和其他人阻止诈骗电子邮件  /  删除重复的电子邮件  /  高级搜索  /  合并文件夹 ...

📁 附件专业版批量保存  /  批量分离  /  批量压缩  /  自动保存   /  自动分离  /  自动压缩 ...

🌟 界面魔法: 😊更多又漂亮又酷的表情符号   /  使用选项卡式视图提高 Outlook 工作效率  /  最小化 Outlook 而不是关闭 ...

👍 一键奇迹: 使用传入附件回复全部  /   反网络钓鱼电子邮件  /  🕘显示发件人的时区 ...

👩🏼‍🤝‍👩🏻 通讯录和日历: 从选定的电子邮件中批量添加联系人  /  将联系人组拆分为各个组  /  删除生日提醒 ...

超过 100特点 等待您的探索! 单击此处了解更多。

了解更多       免费下载      购买
 

 

Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi skyyang,

I need the macro to insert only the first name of the person I receive the email from. Not all the names from CC, but not to remove anyone. Also, to maintain my default color scale (R: 31, G: 73, B: 125) and font size (11 pt) with an additional line after the sender name. Please help me with this. Thanks in advance
This comment was minimized by the moderator on the site
Bonjour,
Puis je avoir le code VBA pour insérer "Bonjour prénom," seulement ???

Merci de votre aide.
This comment was minimized by the moderator on the site
Hello, Nicolas
Please apply the below code:
Public WithEvents GExplorer As Outlook.Explorer
Public WithEvents GMailItem As Outlook.MailItem
Private Sub Application_Startup()
    Set GExplorer = Outlook.Application.ActiveExplorer
End Sub
Private Sub GExplorer_SelectionChange()
    Dim xItem As Object
    On Error Resume Next
    Set xItem = GExplorer.Selection.Item(1)
    If xItem.Class <> olMail Then Exit Sub
    Set GMailItem = xItem
End Sub
Private Sub GMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
    AutoAddGreetingToReply Response
End Sub
Private Sub GMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    AutoAddGreetingToReply Response
End Sub
Sub AutoAddGreetingToReply(Item As Object)
    Dim xReplyMail As MailItem
    Dim xSenderName As String
    Dim xRecipient As Recipient
    On Error Resume Next
    If Item.Class <> olMail Then Exit Sub
    Set xReplyMail = Item
    For Each xRecipient In xReplyMail.Recipients
        If xSenderName = "" Then
            xSenderName = xRecipient.Name
        Else
            xSenderName = xSenderName & "," & xRecipient.Name
        End If
    Next xRecipient
    With xReplyMail
        .Display
        .HTMLBody = "<HTML><Body>Dear " & xSenderName & ",</HTML></Body>" & .HTMLBody
    End With
End Sub

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi.
What do i need to edit in the VBA code to include first name only and to omit the "(s)" after Dear?
Thanks
This comment was minimized by the moderator on the site
Hello, Matt,
To solve your problem, the follwoing VBA code may do you a favor:
Public WithEvents GExplorer As Outlook.Explorer
Public WithEvents GMailItem As Outlook.MailItem
Private Sub Application_Startup()
  Set GExplorer = Outlook.Application.ActiveExplorer
End Sub
Private Sub GExplorer_SelectionChange()
  Dim xItem As Object
  On Error Resume Next
  Set xItem = GExplorer.Selection.Item(1)
  If xItem.Class <> olMail Then Exit Sub
  Set GMailItem = xItem
End Sub
Private Sub GMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
  AutoAddGreetingToReply Response
End Sub
Private Sub GMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
  AutoAddGreetingToReply Response
End Sub
Sub AutoAddGreetingToReply(Item As Object)
  Dim xGreetStr As String
  Dim xReplyMail As MailItem
  Dim xSenderName As String
  Dim xRcpName As String
  Dim xRecipient As Recipient
  Dim xContactItem As ContactItem
  Dim xExUser As ExchangeUser
  On Error Resume Next
  If Item.Class <> olMail Then Exit Sub
  Set xReplyMail = Item
  xSenderName = ""
  xRcpName = ""
  For Each xRecipient In xReplyMail.Recipients
    Set xExUser = Nothing
    Set xContactItem = Nothing
    If xRecipient.AddressEntry.AddressEntryUserType < 6 Then
      Set xExUser = xRecipient.AddressEntry.GetExchangeUser
    Else
      Set xContactItem = xRecipient.AddressEntry.GetContact
    End If
    If Not xExUser Is Nothing Then
      If xSenderName = "" Then
        xSenderName = xExUser.FirstName
        If xSenderName = "" Then
          xSenderName = xRecipient.Name
        End If
      Else
        xSenderName = xSenderName & ", " & xExUser.FirstName
        If xExUser.FirstName = "" Then
          xSenderName = xSenderName & xRecipient.Name
        End If
      End If
    ElseIf Not xContactItem Is Nothing Then
      If xSenderName = "" Then
        xSenderName = xContactItem.FirstName
        If xSenderName = "" Then
          xSenderName = xRecipient.Name
        End If
      Else
        xSenderName = xSenderName & ", " & xContactItem.FirstName
        If xRecipient.FirstName = "" Then
          xSenderName = xSenderName & xRecipient.Name
        End If
      End If
    Else
      If xSenderName = "" Then
        xSenderName = xRecipient.Name
      Else
        xSenderName = xSenderName & ", " & xRecipient.Name
      End If
    End If
  Next xRecipient
  Select Case Time
    Case 0.3 To 0.5
      xGreetStr = " Good morning!"
    Case 0.5 To 0.75
      xGreetStr = " Good afternoon!"
    Case Else
      xGreetStr = " Good evening!"
  End Select
  With xReplyMail
    .Display
    .HTMLBody = "<HTML><Body>Dear " & xSenderName & ",</HTML></Body>" & xGreetStr & .HTMLBody
  End With
End Sub

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hello
Thank you for the suggestions, although it does not work. I wish to include the first name only and to omit the "(s)" after Dear?
This comment was minimized by the moderator on the site
Hello, Matt,
The above code works well.
First, you must make sure the recipient address has been added into the Contact folder in your Outlook.
If the recipient isn't in the Contact folder, when you applying this code, the full nae will be displayed.
Thank you!
This comment was minimized by the moderator on the site
Hello

Thank you for your reply! I will add contacts to my folder. I was wondering if there is a way to always display the first name only, even without contacts within my folder. For context, I work at a large university, and would be difficult and time-consuming to find all staff members individually.
This comment was minimized by the moderator on the site
Hello, Matt,

Sorry, if you haven't added the contact to the contact folder, the code will not get the recipient's first name.
Thank you!
This comment was minimized by the moderator on the site
Hi.
What do i need to edit in the VBA code to include first name only and to omit the "(s)" after Dear?
Thanks
This comment was minimized by the moderator on the site
Dear Team,

If I have set up the above configuration however, if I am replying to an email that has multiply recipients in the To, the greeting is not defaulting. How do I achieve this?
This comment was minimized by the moderator on the site
Hello, Wesley,
Yes, as you said, if there are multiple recipients in the To field, the greeting will not be inserted by default.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations