'Insert Signature in Outlook Email

I found this code, but it doesn't include the signature. In all the resources I've read, I couldn't come up with a solution.

Public Function Email_Test()

Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim objOutlook As Object
Dim Attach As String

Set MyOutlook = New Outlook.Application

Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = "[email protected]" '**put in reference to form

'MyMail.CC = MailList("Copy To")

MyMail.Subject = "This Is A Test Email" '**put in reference for subject

MyMail.Body = "Hi," & vbNewLine & vbNewLine & "See attached."

'MyMail.Send
MyMail.Display

Set MyMail = Nothing
Set MyOutlook = Nothing

End Function


Solution 1:[1]

Here is an example of code I used to attach signature to mail.

Sub Email()
     'Working in 2000-2010
     'This example send the last saved version of the Activeworkbook
    Dim OutApp As Object
    Dim OutMail As Object
    Dim Path As String:  Path = Sheet10.Range("H6").Text & " " & Sheet10.Range("I6").Text
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "Attached updated Stock."

    On Error Resume Next
    With OutMail
        .Display
        .To = "[email protected]"
        .CC = ""
        .BCC = ""
        .Subject = "Fruits Stock " & Path
        .HTMLBody = strbody & .HTMLBody
        .Attachments.Add ActiveWorkbook.FullName
         'You can add other files also like this
         '.Attachments.Add ("C:\test.txt")

    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Solution 2:[2]

Outlook is an HTML application. You will need to use the .HTMLBody and at the end of any text you may put in make sure to include .HTMLBody = "text"& .HTMLBody. This .HTMLBody has to be at the end of any body portion of your email for the signature to appear automatically. I would avoid trying to use multiple body types and just stick with HTML when coding for Outlook. When coding for Outlook use the general format provided in the link by @shmicah in the comments. If your signature does not appear where you want it then add
for each line you need to go down.

Solution 3:[3]

Signatures are added by MailItem.Display only if the message body was not modified before Display is called. Call Display first, and only then merge existing message body (which will include the signature) with your own data. And if you want to preserve the formatting, you will need to work with the HTMLBody property, not the plain text Body. But that will mean you must merge two HTML strings appropriately - you cannot just concatenate them.

If using Redemption (I am its author) is an option, it exposes the RDOSignature object. You can use its ApplyTo method to insert any signature into any message - it takes of the correctly merging the HTML, including styles and embedded mage attachments.

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Drafts = Session.GetDefaultFolder(olFolderDrafts)
set Msg = Drafts.Items.Add
Msg.To = "[email protected]"
Msg.Subject = "testing signatures"
Msg.HTMLBody = "<html><body>some <b>bold</b> message text<br></body></html>"
set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account
if Not (Account Is Nothing) Then
  set Signature = Account.NewMessageSignature
  if Not (Signature Is Nothing) Then
    Signature.ApplyTo Msg, false 'apply at the bottom
  End If
End If
Msg.Display

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 MartyMcfly0033
Solution 3