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

or

Sut i newid llofnod yn awtomatig yn seiliedig ar dderbynwyr yn Outlook?

Yn ddiofyn, mae gan Outlook swyddogaeth adeiladu i ddefnyddwyr newid llofnod yn awtomatig wrth anfon e-byst trwy wahanol gyfrifon e-bost. Ond y tu hwnt i hynny, yma byddaf yn dangos i chi ddull o newid llofnod yn awtomatig yn seiliedig ar wahanol dderbynwyr yn y maes To yn Outlook.

Newid llofnod yn seiliedig ar dderbynwyr yn awtomatig gyda chod VBA


Newid llofnod yn seiliedig ar dderbynwyr yn awtomatig gyda chod VBA

Dilynwch y camau isod i gymhwyso gwahanol lofnodion i dderbynwyr cyfatebol wrth anfon e-byst yn Outlook.

1. Yn gyntaf, mae angen i chi analluogi'r nodwedd llofnod ynghlwm yn Outlook. Cliciwch ffeil > Dewisiadau i agor y Dewisiadau Outlook ffenestr.

2. Yn y Dewisiadau Outlook ffenestr, dewiswch bost yn y cwarel chwith, yna cliciwch ar y Llofnodion botwm yn y Cyfansoddi negeseuon adran. Gweler y screenshot:

3. Yn y Llofnodion a Deunydd Ysgrifennu blwch deialog, ewch i'r Dewiswch lofnod diofyn adran o dan yr Llofnod E-bost tab, dewiswch gyfrif e-bost yn y Cyfrif e-bost rhestr ostwng, ac yna dewis (Dim) oddi wrth y Negeseuon newydd a Atebion / ymlaen rhestrau gwympo. Ailadroddwch y camau hyn nes bod yr holl gyfrifon e-bost wedi'u gosod (Dim). Yna cliciwch y OK botwm.

Nodyn: Gallwch hefyd greu eich llofnodion angenrheidiol yn hyn Llofnodion a Deunydd Ysgrifennu blwch deialog.

4. Cliciwch ar y OK botwm pan fydd yn dychwelyd y Dewisiadau Outlook ffenestr.

5. Gwasgwch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

6. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch ddwywaith ThisOutlookSession yn y cwarel chwith i agor ffenestr y Cod, a'r copi o dan god VBA i'r ffenestr. Gweler y screenshot:

Cod VBA: Newid llofnod yn awtomatig yn seiliedig ar dderbynwyr yn 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

Nodiadau:

  • 1). Yn y cod VBA, disodli'r “Cyfeiriad E-bost 1/2/3/4”Gyda chyfeiriadau e-bost penodol y derbynwyr.
  • 2). "aaa.htm""bbb.htm"A"ccc.htm"yw'r llofnod penodedig y byddwch chi'n ei anfon at dderbynwyr cyfatebol.
  • 3). Yn yr achos hwn, llofnod “aaaYn cael ei anfon at “Cyfeiriad E-bost 1", llofnod "BBBYn cael ei anfon at “Cyfeiriad E-bost 2"A"Cyfeiriad E-bost 3", a "Cyfeiriad E-bost 4”Yn derbyn yr e-bost wedi'i fewnosod â llofnod“ccc”. Newidiwch nhw ar sail eich anghenion.
  • 4). Os oes sawl derbynnydd mewn e-bost, dim ond ar gyfer yr un cyntaf y mae'r cod yn gweithio. A bydd pob derbynnydd yn derbyn yr e-bost gyda'r un llofnod wedi'i nodi i'r derbynnydd hwnnw.

7. Yna cliciwch offer > cyfeiriadau i fynd i'r Cyfeiriadau-Prosiect blwch deialog. Yn y dialog, gwiriwch y ddau Llyfrgell Gwrthrychau Microsoft Word a'r Microsoft Scripting Runtime opsiynau, ac yna cliciwch OK botwm, gweler y screenshot:

8. Gwasgwch y Alt + Q allweddi i gau'r Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

O hyn ymlaen, ar ôl cyfansoddi e-bost a tharo'r botwm Anfon, bydd y llofnod cyfatebol yn cael ei fewnosod yn awtomatig ar ddiwedd y corff e-bost yn seiliedig ar gyfeiriad e-bost y derbynnydd yn y maes To.


Mewnosod y Dyddiad Cyfredol yn Llofnod yn Awtomatig Wrth Anfon E-bost Mewn Rhagolwg:

Os ydych chi am fewnosod stamp amser fel llofnod yn y corff e-bost wrth greu / ateb / anfon e-bost newydd yn eich Camre, gallwch chi alluogi'r Ychwanegwch lofnod dyddiad wrth greu e-bost newydd, ateb ac ymlaen opsiwn o Kutools ar gyfer Rhagolwg i'w gyflawni. Gweler y screenshot:
Dadlwythwch a rhoi cynnig arni nawr (llwybr am ddim 60 diwrnod)


Kutools for Outlook - Yn Dod â 100 o Nodweddion Uwch i'w Rhagweld, a Gwneud Gwaith yn Haws Osgach!

  • Auto CC / BCC yn ôl rheolau wrth anfon e-bost; Auto Ymlaen E-byst Lluosog yn ôl arfer; Ymateb Auto heb weinydd cyfnewid, a nodweddion mwy awtomatig ...
  • Rhybudd BCC - dangoswch neges pan geisiwch ateb popeth os yw'ch cyfeiriad post yn rhestr BCC; Atgoffwch Wrth Ymlyniadau ar Goll, a mwy o nodweddion atgoffa ...
  • Ymateb (Pawb) Gyda'r Holl Atodiadau yn y sgwrs bost; Ateb Llawer o E-byst mewn eiliadau; Auto Ychwanegu Cyfarchiad wrth ateb; Ychwanegu Dyddiad i'r pwnc ...
  • Offer Ymlyniad: Rheoli Pob Atodiad ym mhob Post, Datgysylltiad Auto, Cywasgu Pawb, Ail-enwi Pawb, Arbed Pawb ... Adroddiad Cyflym, Cyfrif Postiau Dethol...
  • E-byst Sothach Pwerus yn ôl arfer; Tynnwch y Post a Chysylltiadau Dyblyg... Yn eich galluogi i wneud yn ddoethach, yn gyflymach ac yn well yn Outlook.
tab kutools rhagweld kutools tab 1180x121
kutools rhagweld rhagolygon kutools ynghyd â thab 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 · 5 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.