Перейти до основного матеріалу

Як автоматично створити ім’я дорогого відправника під час відповіді на повідомлення в Outlook?

Відповідаючи на повідомлення електронної пошти, слід вручну ввести ім’я відправника та привітання. Щоб заощадити час та підвищити ефективність роботи, ви можете розглянути можливість створення імені шановного відправника та привітання автоматично в Outlook. У цій статті я розповім про деякі корисні методи вирішення цього завдання в Outlook.

Автоматично створюйте ім’я та привітання дорогого відправника, відповідаючи на повідомлення з кодом VBA

Автоматично створюйте ім’я шановного відправника та привітання під час відповіді на повідомлення за допомогою Kutools для Outlook


Автоматично створюйте ім’я та привітання дорогого відправника, відповідаючи на повідомлення з кодом VBA

Наступний код VBA може допомогти вам автоматично вставити ім'я та привітання дорогого відправника під час відповіді на повідомлення електронної пошти. Будь ласка, зробіть так:

1. Утримуйте клавішу ALT + F11 ключі, щоб відкрити Microsoft Visual Basic для додатків вікна.

2, в Microsoft Visual Basic для додатків вікно, двічі клацніть ThisOutlookSession від Проект1 (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 auto шановне ім'я відправника 1

3. Потім закрийте Outlook і перезапустіть його, щоб надати ефект коду, і тепер, коли ви відповідаєте на повідомлення електронної пошти, ім’я та привітання дорогого відправника автоматично вставляються в тіло, див. Знімок екрана:

doc auto шановне ім'я відправника 2


Автоматично створюйте ім’я шановного відправника та привітання під час відповіді на повідомлення за допомогою Kutools для Outlook

Якщо у вас є Kutools для Outlook, З його Додайте привітання під час відповіді Функція Outlook автоматично відповідає за ім’я відправника.

Kutools для Outlook : з більш ніж 100 зручними надбудовами Outlook, які можна спробувати без обмежень протягом 60 днів. 

після установки Kutools для Outlook, будь ласка, зробіть так:

1. Клацання Кутулс > Опції, див. скріншот:

doc auto шановне ім'я відправника 3

2, в Опції у діалоговому вікні під відповісти вкладка, перевірити Додайте привітання під час відповіді , а потім введіть привітання, як вам потрібно, див. знімок екрана:

doc auto шановне ім'я відправника 4

3. Потім натисніть OK щоб закінчити це налаштування, відтепер при відповіді на повідомлення привітання автоматично створюватиметься перед тілом повідомлення, див. знімок екрана:

doc auto шановне ім'я відправника 5

Натисніть, щоб завантажити Kutools для Outlook і безкоштовну пробну версію зараз!


Найкращі інструменти продуктивності офісу

Kutools для Outlook - Понад 100 потужних функцій, які покращать ваш Outlook

🤖 AI Mail Assistant: Миттєві професійні електронні листи з магією штучного інтелекту – геніальні відповіді одним клацанням, ідеальний тон, багатомовна майстерність. Трансформуйте електронну пошту без зусиль! ...

???? Автоматизація електронної пошти: Поза офісом (доступно для POP та IMAP)  /  Розклад надсилання електронних листів  /  Автоматична копія/прихована копія за правилами під час надсилання електронної пошти  /  Автоматичне пересилання (розширені правила)   /  Автоматично додавати привітання   /  Автоматично розділяйте електронні листи кількох одержувачів на окремі повідомлення ...

📨 Управління електронною поштою: Легко відкликайте електронні листи  /  Блокуйте шахрайські електронні листи за темами та іншими  /  Видалити повторювані електронні листи  /  розширений пошук  /  Консолідація папок ...

📁 Вкладення ProПакетне збереження  /  Пакетне від'єднання  /  Пакетний компрес  /  Автозавантаження   /  Автоматичне від'єднання  /  Автокомпресія ...

???? Магія інтерфейсу: 😊Більше красивих і класних смайликів   /  Підвищте продуктивність 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