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"
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!
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
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!
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!
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.
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.