Kutools for Excel 22.00 HOT

300+ Powerful Features You Must Have in Excel

Kutools-for-Excel

Kutools for Excel is a powerful add-in that frees you from performing time-consuming operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful features / functions for Excel 2019, 2016, 2013, 2010, 2007 or Office 365!

Read More Download Buy now

Office Tab 14.00HOT

Adding Tabbed Interface for Office

Office Tab

It enables tabbed browsing, editing, and managing of Microsoft Office applications. You can open multiple documents / files in a single tabbed window, such as using the browser IE 8/9/10, Firefox, and Google Chrome. It's compatible with Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365. Demo

Read More Download Buy now

Kutools for Outlook 13.00NEW

100+ Powerful Features for Outlook

Kutools-for-Outlook

Kutools for Outlook is a powerful add-in that frees you from time-consuming operations which majority of Outlook users has to perform daily! It can save your time from using Microsoft Outlook 2019, 2016, 2013, 2010 or Office 365!

Read More Download Buy now

Kutools for Word  9.00NEW

100+ Powerful Features for Word

Kutools-for-Word

Kutools for Word is a powerful add-in that frees you from time-consuming operations which majority of Word users have to perform daily! It can save your time from using Microsoft Word / Office 2019, 2016, 2013, 2010, 2007, 2003 or Office 365!

Read More Download Buy now

Classic Menu for Office

Bringing Back Your Familiar Menus

Restores the old look and menus of Office 2003 to Microsoft Office 2019, 2016, 2013, 2010, 2007 or Office 365. Don’t lose time in finding commands on the new Ribbon. Easy to deploy to all computers in enterprises and organizations.

Read More Download Buy now

How to automatically change signature based on recipients in Outlook?

By default, Outlook has a build-in function for users to automatically change signature while sending emails through different email accounts. But beyond that, here I will show you method of automatically changing signature based on different recipients in the To field in Outlook.

Change signature based on recipients automatically with VBA code


Change signature based on recipients automatically with VBA code

Please follow the below steps to apply different signatures to corresponding recipients while sending emails in Outlook.

1. Firstly, you need to disable the auto attached signature feature in Outlook. Please click File > Options to open the Outlook Options window.

2. In the Outlook Options window, select Mail in the left pane, then click the Signatures button in the Compose messages section. See screenshot:

3. In the Signatures and Stationery dialog box, go to the Choose default signature section under the E-mail Signature tab, select an email account in the Email-account drop-down list, and then choose (none) from the New messages and Replies/forwards drop-down lists. Repeat these steps until all email accounts are set to (none). Then click the OK button.

Note: You can also create your needed signatures in this Signatures and Stationery dialog box.

4. Click the OK button when it returns the Outlook Options window.

5. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

6. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession in the left pane to open the Code window, and the copy below VBA code into the window. See screenshot:

VBA code: Automatically change signature based on recipients in Outlook

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Updated by ExtendOffice 2020/6/12
Dim xMailItem As MailItem
Dim xRecipients As Recipients
Dim xRecipient As Recipient
Dim xRcpAddress As String
Dim xSignatureFile, xSignaturePath As String
Dim xFSO As Scripting.FileSystemObject
Dim xDoc As Document
On Error Resume Next
Set xFSO = New Scripting.FileSystemObject
If Item.Class <> olMail Then Exit Sub
Set xMailItem = Item
Set xRecipients = xMailItem.Recipients
xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
For Each xRecipient In xRecipients
    If xRecipient.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
        xRcpAddress = xRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    Else
        xRcpAddress = xRecipient.AddressEntry.Address
    End If
    Select Case xRcpAddress
        Case "Email Address 1"
            xSignatureFile = xSignaturePath & "aaa.htm"
            Exit For
        Case "Email Address 2", "Email Address 3"
            xSignatureFile = xSignaturePath & "bbb.htm"
            Exit For
        Case "Email Address 4"
            xSignatureFile = xSignaturePath & "ccc.htm"
            Exit For
    End Select
Next
VBA.DoEvents
Set xDoc = xMailItem.GetInspector.WordEditor
xDoc.Application.Selection.EndKey
xDoc.Application.Selection.InsertParagraphAfter
xDoc.Application.Selection.MoveDown Unit:=wdLine, Count:=1
xDoc.Application.Selection.InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
End Sub

Notes:

  • 1). In the VBA code, please replace the “Email Address 1/2/3/4” with the certain email addresses of the recipients.
  • 2). "aaa.htm", "bbb.htm" and "ccc.htm" are the specified signature you will send to corresponding recipients.
  • 3). In this case, signature “aaa” will be sent to “Email Address 1”, signature “bbb” will be sent to “Email Address 2” and “Email Address 3, and “Email Address 4” will receive the email embedded with signature “ccc”. Please change them based on your needs.
  • 4). If there are multiple recipients in an email, the code only works for the first one. And all recipients will receive the email with the same signature specified to that recipient.

7. Then click Tools > References to go to the References-Project dialog box. In the dialog, please check both the Microsoft Word Object Library and the Microsoft Scripting Runtime options, and then click OK button, see screenshot:

8. Press the Alt + Q keys to close the Microsoft Visual Basic for Applications window.

From now on, after composing an email and hitting the Send button, the corresponding signature will be automatically inserted at the end of the email body based on the recipient’s email address in the To field.


Automatically Insert Current Date as Signature When Sending Email In Outlook:

If you want to insert timestamp as signature into the email body while creating/replying/forwarding new email in your Outlook, you can enable the Add date signature when create new, reply and forward email option of Kutools for Outlook to acheive it. See screenshot:
Download and try it now ( 60-day free trail)


Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
 
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    pauli · 2 months ago
    Hi, I would like to apply this to differentiate signatures when sending internal and external emails. Therefore instead of recognizing specific email addresses I'd need to just differentiate by the recipient email address containing my firm's name inside it or not. Could you let me know how the code would be for this specific case?


    (For example if i wanted to sign with signature "internal.htm" when the recipient email contains the string "microsoft" and signature "external.htm" if it doesn't contain the string "microsoft". In this case addresses like 'jane@microsoft.com', 'tom@microsoft.support.com' and 'recruiting@microsoft.europe.com' would all be considered like the internal recipients for a Microsoft employee).

    Thanks!!
    • To post as a guest, your comment is unpublished.
      crystal · 1 months ago
      Hi pauli,
      Please try the below code. Before applying the code, please go to the References dialog to check the Microsoft Word Object Library box (as the attached image shown).

      Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
      'Updated by ExtendOffice 2020/6/12
      Dim xMailItem As MailItem
      Dim xRecipients As Recipients
      Dim xRecipient As Recipient
      Dim xRcpAddress As String
      Dim xSignatureFile, xSignaturePath As String
      Dim xFSO As Scripting.FileSystemObject
      Dim xDoc As Document
      On Error Resume Next
      Set xFSO = New Scripting.FileSystemObject
      If Item.Class <> olMail Then Exit Sub
      Set xMailItem = Item
      Set xRecipients = xMailItem.Recipients
      xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
      For Each xRecipient In xRecipients
      If xRecipient.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
      xRcpAddress = xRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
      Else
      xRcpAddress = xRecipient.AddressEntry.Address
      End If
      If VBA.InStr(VBA.LCase(xRcpAddress), "@microsoft") > 0 Then 'Enter the string in the double quotation marks. If the recipient email address contains this string, the below signature "internal.htm" will be assigned to the email. Otherwise, assign the signature "external.htm".
      xSignatureFile = xSignaturePath & "internal.htm"
      Exit For
      Else
      xSignatureFile = xSignaturePath & "external.htm"
      End If
      Next
      VBA.DoEvents
      Set xDoc = xMailItem.GetInspector.WordEditor
      xDoc.Application.Selection.EndKey
      xDoc.Application.Selection.InsertParagraphAfter
      xDoc.Application.Selection.MoveDown Unit:=wdLine, Count:=1
      xDoc.Application.Selection.InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
      End Sub
  • To post as a guest, your comment is unpublished.
    calo.andrea.sportradar@gmail.com · 6 months ago
    Hi Crystal,

    what did you change to fix the images issue? I am using your latest code and I have the same problem as Amanda.
    Thanks
    • To post as a guest, your comment is unpublished.
      crystal · 1 months ago
      Besides the code, the operation of step 7 has also changed. Please follow the instruction step by step to get it down.
    • To post as a guest, your comment is unpublished.
      crystal · 1 months ago
      Hi,
      Sorry for the mistake. The VBA has been updated again, and the images issue is totally fixed now.
  • To post as a guest, your comment is unpublished.
    Vysakh · 6 months ago
    Very nice script but the image files in my signature are not delivered right. Can you fix this issue ?
    • To post as a guest, your comment is unpublished.
      crystal · 1 months ago
      Hi Vysakh,
      The code has been updated, and the images issue is fixed now. Sorry for the inconvenience.
  • To post as a guest, your comment is unpublished.
    Amanda · 8 months ago
    I added this clever script to Outlook 2013 and it correctly identifies and selects the different email signatures I use.

    I have a problem with one of the graphics that is part of one signature. Instead of the graphic being shown the "Sent Items" folder (and recipient) shows the email with the attached screen shot and trying to download the image does not work.

    If I disable the script and sign manually then the outgoing email is correct and the recipient gets what I intend. Even more interesting is that with another simpler signature where the graphic is just a straight line this is included albeit that the graphic is changed slightly.

    The graphic is a PNG file 80KB 5904 x 1024 pixels with a bit depth of 32 and I have tried smaller sizes down to 10KB 369 x 64 pixels which has not helped. My Outlook version is 15.0.5189.1000 32Bit Professional Plus 2013 on a Windows 10 Pro platform.

    I wonder if you can suggest a solution for this please.
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Dear Amanda,
      We have updated the code. Thank you for reminding me the error.
  • To post as a guest, your comment is unpublished.
    gregoryt · 1 years ago
    Hello! Very nice script, but there is a problem when sending to excahnge addresses, the xRcpAddress returns the X400 name not the smtp address, this makes it impossible to select based on domain. Is there a workaround this?


    Just to improve I have changed the case statement to if using the inStr function to discern mails in bulk

    If InStr(xRcpAddress, "@example") Then
    xSignatureFile = xSignaturePath & "aaa.htm"
    End If
  • To post as a guest, your comment is unpublished.
    Devansh · 1 years ago
    How would this behave if there are multiple recipients?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Devansh,
      If there are multiple recipients in an email, the code only works for the first one. And all recipients will receive the email with the same signature specified to that person.
      If you want to incude different signatures when there are multiple recipients, the email should be sent separately to different recipients. And that will need another code to achieve.

Feature Tutorials