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"
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.
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 2019/04/29 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 xTextStream As Scripting.TextStream Dim xSignature As String 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 xRcpAddress = xRecipient.Address 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 Set xTextStream = xFSO.OpenTextFile(xSignatureFile) xSignature = xTextStream.ReadAll xMailItem.HTMLBody = xMailItem.HTMLBody & "" & xSignature & "" End Sub
7. Then click Tools > References to go to the References-Project dialog box. In the dialog, please check Microsoft Scripting Runtime option, 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.