Note: The other languages of the website are Google-translated. Back to English
Inloggen  \/ 
x
or
x
Registreer  \/ 
x

or

Hoe de handtekening automatisch te wijzigen op basis van ontvangers in Outlook?

Outlook heeft standaard een ingebouwde functie waarmee gebruikers automatisch de handtekening kunnen wijzigen tijdens het verzenden van e-mails via verschillende e-mailaccounts. Maar verder zal ik u hier de methode laten zien om de handtekening automatisch te wijzigen op basis van verschillende ontvangers in het veld Aan in Outlook.

Wijzig de handtekening op basis van ontvangers automatisch met VBA-code


Wijzig de handtekening op basis van ontvangers automatisch met VBA-code

Volg de onderstaande stappen om verschillende handtekeningen toe te passen op de corresponderende ontvangers tijdens het verzenden van e-mails in Outlook.

1. Ten eerste moet u de functie voor automatisch bijgevoegde ondertekening in Outlook uitschakelen. Klik alstublieft Dien in > Opties om de te openen Outlook Opties venster.

2. In de Outlook Opties venster, selecteer E-mailadres in het linkerdeelvenster en klik vervolgens op het handtekeningen knop in de Berichten opstellen sectie. Zie screenshot:

3. In de Handtekeningen en briefpapier dialoogvenster, ga naar het Kies standaardhandtekening sectie onder de Email handtekening Selecteer een e-mailaccount in het Email account vervolgkeuzelijst en kies vervolgens (Geen) van de Nieuwe berichten als Antwoorden / doorsturen vervolgkeuzelijsten. Herhaal deze stappen totdat alle e-mailaccounts zijn ingesteld op (Geen). Klik vervolgens op de OK knop.

Opmerking:: U kunt hierin ook uw benodigde handtekeningen maken Handtekeningen en briefpapier dialoog venster.

4. Klik op het OK knop wanneer het terug de Outlook Opties venster.

5. druk de anders + F11 toetsen om de te openen Microsoft Visual Basic voor toepassingen venster.

6. In de Microsoft Visual Basic voor toepassingen venster, dubbelklik DezeOutlookSessie in het linkerdeelvenster om het codevenster te openen en de kopie onder VBA-code naar het venster. Zie screenshot:

VBA-code: automatisch de handtekening wijzigen op basis van ontvangers 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). Vervang in de VBA-code de “E-mailadres 1/2/3/4”Met de bepaalde e-mailadressen van de ontvangers.
  • 2). "aaa.htm''bbb.htm"En"ccc.htm"zijn de gespecificeerde handtekening die u naar de corresponderende ontvangers stuurt.
  • 3). In dit geval handtekening ‘aaa"Wordt verzonden naar"E-mailadres 1", Handtekening"bbb"Wordt verzonden naar"E-mailadres 2"En"E-mailadres 3"en "E-mailadres 4"Ontvangt de e-mail ingesloten met handtekening"ccc”. Wijzig ze op basis van uw behoeften.
  • 4). Als er meerdere ontvangers in een e-mail zijn, werkt de code alleen voor de eerste. En alle ontvangers ontvangen de e-mail met dezelfde handtekening die is opgegeven voor die ontvanger.

7. Dan klikken Toolbox > Referenties naar de Referenties-Project dialoog venster. Controleer in het dialoogvenster beide Microsoft Word-objectbibliotheek en Microsoft Scripting Runtime opties en klik vervolgens op OK knop, zie screenshot:

8. druk de anders + Q toetsen om de Microsoft Visual Basic voor toepassingen venster.

Vanaf nu, na het opstellen van een e-mail en het klikken op de knop Verzenden, wordt de bijbehorende handtekening automatisch ingevoegd aan het einde van de e-mailtekst op basis van het e-mailadres van de ontvanger in het veld Aan.


Voeg automatisch de huidige datum in als handtekening bij het verzenden van e-mail in Outlook:

Als u een tijdstempel als handtekening in de e-mailtekst wilt invoegen tijdens het maken / beantwoorden / doorsturen van nieuwe e-mail in uw Outlook, kunt u de Voeg een datumhandtekening toe bij het maken van nieuwe, beantwoord en stuur e-mail door optie van Kutools for Outlook om het te bereiken. Zie screenshot:
Download en probeer het nu (gratis proef van 60 dagen)


Kutools voor Outlook - Brengt 100 geavanceerde functies naar Outlook en maakt het werk veel gemakkelijker!

  • Auto CC / BCC volgens regels bij het verzenden van e-mail; Automatisch doorsturen Meerdere e-mails op maat; Auto antwoord zonder uitwisselingsserver, en meer automatische functies ...
  • BCC-waarschuwing - toon bericht wanneer u alle probeert te beantwoorden als uw e-mailadres in de BCC-lijst staat; Herinner bij ontbrekende bijlagen, en meer herinneren functies ...
  • Beantwoorden (alle) met alle bijlagen in het e-mailgesprek; Beantwoord veel e-mails in seconden; Begroeting automatisch toevoegen wanneer antwoord; Datum toevoegen aan onderwerp ...
  • Hulpmiddelen voor bijlagen: beheer alle bijlagen in alle e-mails, Automatisch loskoppelen, Alles comprimeren, Alles hernoemen, Alles opslaan ... Snel rapport, Tel geselecteerde e-mails...
  • Krachtige ongewenste e-mails op maat; Verwijder dubbele e-mails en contacten... Stel u in staat om slimmer, sneller en beter te doen in Outlook.
shot kutools outlook kutools tabblad 1180x121
shot kutools vooruitzichten kutools plus tabblad 1180x121
 
Say something here...
symbols left.
You are guest
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.
    Seth · 2 months ago
    This script is great and functional for what I was looking for. Is it possible to have the code differentiate if the message is new or a reply as well as the email domain? For example to further select a separate signature for replies to external recipients vs a new message to external recipients?

    Thank you for sharing.
  • To post as a guest, your comment is unpublished.
    jcamino · 6 months ago
    Great script. Thank you.Any way to insert the signature before hitting send to preview. I know I can delay send and look at it in outbox. Currently it doesn't appear until I hit send. If not is there any software that will automatically assign a signature based on Contact. We have been using a program for many years that worked great but it does not work in new versions of Outlook.
  • To post as a guest, your comment is unpublished.
    TimS · 8 months ago
    Hello Crystal,

    I am interested in the VBA code you wrote for "pauli" below, but when I run it, the following error is generated (and the "XDoc as Document" code line is highlighted):

    "Compile error: User-defined type not defined"

    How can I resolve this issue please?

    Thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi Tim,
      Before applying the code, please go to the References dialog to check the Microsoft Word Object Library box (as the attached image shown).
  • To post as a guest, your comment is unpublished.
    Tim · 8 months ago
    Hello Crystal,

    I am interested in the VBA code you wrote for "pauli" below, but when I run it, the following error is generated (and the "XDoc as Document" code line is highlighted):

    "Compile error: User-defined type not defined"

    How can I resolve this issue please?

    Thank you, Tim
  • To post as a guest, your comment is unpublished.
    Greg · 11 months ago
    Tim I have same issue. Wherever the user clicks last is where the image is inserted. Does anyone have a way to force the image just above the signature?
  • To post as a guest, your comment is unpublished.
    Tim · 1 years ago
    I have some weird behaviour with VBA-generated Outlook emails. The signature is added to the mail as intended, but not positioned in the bottom of the email but rather in the middle (looks like at the first empty space). Any idea why and how to overcome it?
  • To post as a guest, your comment is unpublished.
    pauli · 1 years 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 years 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.
        Daniela · 7 months ago
        Hi, Crystal,
        I have a question. When I am sending emails to both external and internal recipients how can I make it differentiate by choosing always external signature? Thanks
        • To post as a guest, your comment is unpublished.
          Random_Guest · 2 months ago
          You might have found the solution for yourself by now or abandoned this thread long time ago, but I feel the urge to finish this now. The simple answer to this question:

          Edit the If-Else-Clause (that differentiates between the two signatures) to the following:

          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 & "external.htm"
          Exit For
          Else
          xSignatureFile = xSignaturePath & "internal.htm"
          End If

          What happens now:

          If the recipient address from a list of recipient addresses does NOT contain the given string, use the external signature and stop looking at further recipients. Otherwise use the internal signature and look for the next recipient address.
  • To post as a guest, your comment is unpublished.
    calo.andrea.sportradar@gmail.com · 1 years 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 years 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 years 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 · 1 years 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 years 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 · 1 years 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 · 1 years 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 · 2 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 · 2 years ago
    How would this behave if there are multiple recipients?
    • To post as a guest, your comment is unpublished.
      crystal · 2 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.