How to Auto Select Different Signatures for Different Recipients in Your Outlook Emails

Many users hope that Outlook can auto select the different signatures for different recipients in the emails. Thus, this article will teach how to realize it via VBA.

By default, Outlook only allows you to auto insert the varying signature into new emails, replies and forwards. However, many people even hope that Outlook can auto select the different signatures for varying recipients. Unfortunately, Outlook doesn’t provide such a direct feature. Thus, you have to seek other ways, such as any third party add-ins or VBA code. Now, in the followings, we will unveil a piece of VBA code to you, which can help you realize it like a breeze.

Auto Select Different Signatures for Different Recipients in Your Outlook Emails

Auto Select Different Signatures for Different Recipients

  1. To start with, you should launch your Outlook program.
  2. Then you had better disable the auto-insert signature feature.Disable the auto-insert signature feature
  • Firstly, go to “File” menu and select “Options”.
  • In the “Outlook Options” window, switch to “Mail” tab.
  • Then find and click on “Signatures” button.
  • Next in the popup dialog box, set “(none)” in the both “New Messages” and “Replies/Forwards”.
  • After that, click a series of “OK” to save the changes.
  1. After that, you can back to Outlook main window and press “Alt + F11” keys.
  2. Next, in the “Microsoft Visual Basic for Applications” window, find and open the “ThisOutlookSession” project.
  3. Subsequently, copy and paste the following VBA code into this project.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMail As Outlook.MailItem
    Dim objRecipients As Outlook.Recipients
    Dim objRecipient As Outlook.recipient
    Dim strRecipientAddress As String
    Dim strSignatureFile As String
    Dim objFileSystem As Object
    Dim objTextStream As Object
    Dim strSignature As String
    If TypeOf Item Is MailItem Then
       Set objMail = Item
       Set objRecipients = objMail.Recipients
    End If
    'Select different signature files based on recipients
    'You can change the conditions as per you actual needs
    If objRecipients.Count = 1 Then
       Set objRecipient = objRecipients.Item(1)
       strRecipientAddress = objRecipient.Address
       If strRecipientAddress = "" Then
          strSignatureFile = CStr(Environ("USERPROFILE")) & "\AppData\Roaming\Microsoft\Signatures\Test John Smith.htm"
       ElseIf strRecipientAddress = "" Or strRecipientAddress = "" Then
          strSignatureFile = CStr(Environ("USERPROFILE")) & "\AppData\Roaming\Microsoft\Signatures\Johnny.htm"
       ElseIf strRecipientAddress = "" Then
          strSignatureFile = CStr(Environ("USERPROFILE")) & "\AppData\Roaming\Microsoft\Signatures\New John Smith.htm"
       End If
       strSignatureFile = CStr(Environ("USERPROFILE")) & "\AppData\Roaming\Microsoft\Signatures\John Smith.htm"
    End If
    'Read the specific signature file
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objTextStream = objFileSystem.OpenTextFile(strSignatureFile)
    strSignature = objTextStream.ReadAll
    'Insert the signature to this email
    objMail.HTMLBody = objMail.HTMLBody & "<HTML><BODY><br>" & strSignature & "</br></HTML></BODY>"
End Sub

VBA Code - Auto Select Different Signatures for Different Recipients

  1. After that, you should sign this code.
  2. Later change your Outlook macro settings to allow signed macros.
  3. From now on, every time you click “Send” button to send an email, Outlook will identify the recipient and auto insert the corresponding signature at the end of the email body.

Look out for Hidden Malicious Macros in Incoming Emails

Nowadays viruses have become very mature and powerful. They always disguise them as innocuous things in the email. Therefore, now that you intend to utilize macros in Outlook, you should raise your vigilance against the malicious macros. Otherwise, your PST data will be kept in risk. If PST gets corrupt, you’ll try your best to recover PST data. In this case, it’s suggested to apply a potent tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql fix and outlook repair software products. For more information visit

6 responses to “How to Auto Select Different Signatures for Different Recipients in Your Outlook Emails”

  1. My previous comment appears to have had the HTML tags eaten, but basically, currently it says HTML BODY CONTENT HTML BODY, and it should be HTML BODY CONTENT BODY HTML

  2. Looks like an error on the last line:
    objMail.HTMLBody = objMail.HTMLBody & “” & strSignature & “”
    You have the closing BODY tag outside of the HTML one. I.e. it should be:
    objMail.HTMLBody = objMail.HTMLBody & “” & strSignature & “”

    Rest of code completely untested, just happened to notice this while browsing the web.

  3. Found a fix. In order to display the images in the signature, you must edit the .html file for the signature to include the full path for all references. By default they will use all relative references, but these must be changed to pull in images.

  4. Used the code to locate and attach signature to file, but does not import images in the signature, just formatted text. Any way to get the images to show, or is this limited by the html body style? Maybe need to attach the images to file?

  5. Originally the code errored out in setting objTextStream. It appeared strSignatureFile had no value. After adding code to assign a value to strSignatureFile, that eliminated this error.

    Once strSignatureFile was given a value, the above VB then errored out on the test “If objRecipients.Count = 1 then…”. In effect, it appears that the entire If statement is not executed at all since the “Else…” also does not execute. Is it possible that objRecipients.Count is a datatype other than a numeric 1? I did check with a message box to display the value associated with that object and it does “appear” to return a number and theoretically the value was 1 but none of the code that “should have” executed with that value did not. That should have meant the Else code should have executed but did not.

Leave a Reply

Your email address will not be published. Required fields are marked *