Ben H.
Ben H.

Reputation: 134

Include signature in VBA created email Outlook 2013

Here's what I've got. It works to create a message with HTML format, but I want it to include my signature and I'm not sure how to do that. I looked at some other answers and their solutions don't seem to work for Outlook 2013.

 Sub CreateHTMLMail()

'Creates a new email item and modifies its properties.

Dim objMail As MailItem



'Create mail item

Set objMail = Application.CreateItem(olMailItem)

With objMail

'Set body format to HTML

.BodyFormat = olFormatHTML

.HTMLBody = "test"

.Display

End With



End Sub

Upvotes: 0

Views: 112

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

There is no signature-specific property in the Outlook object model. You can detect the existing signature (if any) by reading the existing set of signatures (if any) in the following folders, so if you create a signature in Outlook it will save three files (HTM, TXT and RTF):

  • Vista and Windows 7/8/8.1/10:
C:\Users\<UserName>\AppData\Roaming\Microsoft\Signatures
  • Windows XP :
C:\Documents and Settings\<UserName>\Application Data\Microsoft\Signatures

Application Data and AppData are hidden folders, change the view in Windows explorer so it shows hidden files and folders if you want to see the files.

Outlook adds the signature to the new unmodified messages (you should not modify the body prior to that) when you call MailItem.Display (which causes the message to be displayed on the screen) or when you access the MailItem.GetInspector property - you do not have to do anything with the returned Inspector object, but Outlook will populate the message body with the signature.

Once the signature is added, read the HTMLBody property and merge it with the HTML string that you are trying to set. Note that you cannot simply concatenate two HTML strings - the strings need to be merged. E.g. if you want to insert your string at the top of the HTML body, look for the <body substring, then find the next occurrence of > (this takes care of the <body> element with attributes), then insert your HTML string after that >.

Upvotes: 1

Related Questions